【发布时间】:2021-08-22 00:58:29
【问题描述】:
我想在没有 Django REST 框架的情况下实现它。
这是我的代码:
from django.http import JsonResponse
def index1(request):
cursor.execute('select * from users where id = %s', [request.POST])
response = list(cursor.fetchall())
return JsonResponse(response, safe=False)
当我使用 Flutter HTTP POST 时,它给了我这个
Forbidden (CSRF cookie not set.): /index1
[04/Jun/2021 00:20:25] "POST /index1 HTTP/1.1" 403 2870
【问题讨论】:
-
我对django不熟悉,但我认为错误很明显。您需要提供一个 CSRF 令牌(相应的 cookie)。看看docs。
标签: python django api flutter django-rest-framework