[英]Empty request.POST in a Django view
When sending a POST request to the following view, the request.POST
dictionary is empty: 将POST请求发送到以下视图时,
request.POST
词典为空:
@csrf_exempt
def created_query(request):
if request.method == 'POST':
print(request.POST)
server = get_object_or_404(Server, pk=request.POST['server'])
if server.owner == request.user:
if server.created:
return HttpResponse("created")
else:
return HttpResponse("pending")
else:
return HttpResponseForbidden
else:
return HttpResponseForbidden
I have tried with multiple ways of generating the POST request such as this cURL request: 我尝试了多种生成POST请求的方式,例如以下cURL请求:
curl --request POST \
--url http://localhost:80/created/ \
--form server=60 \
--form action=created
I have checked the dictionary using a debugger as well as just printing it and it is always empty. 我已经使用调试器以及仅打印它检查了字典,并且字典始终为空。 I doubt it is a problem with the
urls.py
however here is the line in the file that handles this view: 我怀疑
urls.py
是否有问题,但是下面是处理此视图的文件所在的行:
url(r'^created/', views.created_query, name='created'),
Things we've already tried: 我们已经尝试过的事情:
Starting at Django 1.5, POST does not contain non-form data anymore. 从Django 1.5开始,POST不再包含非格式数据。
You can use request.body
. 您可以使用
request.body
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.