When sending a POST request to the following view, the request.POST
dictionary is empty:
@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:
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:
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.
You can use request.body
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.