gpt4 book ai didi

python - 错误 : “CSRF verification failed. Request aborted.” when using jquery json with Django

转载 作者:行者123 更新时间:2023-11-28 17:40:10 26 4
gpt4 key购买 nike

我想检索 json 数据并将其放入数据库。我正在使用 Django

当我发布 json 时,我收到此错误:禁止 (403)CSRF 验证失败。请求中止。

代码

def receiver(request):
try:
json_data = request_to_json(request)

# Retrieving json data
x = json_data['x']
y = json_data['y']
z = json_data['z']
# put it in database

db = db_connection().db;
db_manager= db_management(db);
db_manager.insert_point(x,y,z,x);
db.close()

# A variable to return to the app
response = 'OK'

except:
response = 'Error'

return HttpResponse(simplejson.dumps(response))

最佳答案

这是我找到的解决方案:

from django.views.decorators.csrf import csrf_exempt

@csrf_exempt
def my_view(request):
return HttpResponse('Hello world')

关于python - 错误 : “CSRF verification failed. Request aborted.” when using jquery json with Django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25524623/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com