Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django request.post no data available

Tags:

python

django

I have already searched for similar questions on StackOverflow but could not find the solution that would work for me. I have the following code snippet:

def post_request(request):

if request.method == "POST":
    access_token = AccessToken.objects.get(token = request.POST.get("access_token"), expires__gt = timezone.now())

When I make the HTTP request to this function, I get the following error: AccessToken matching query does not exist. , I started debugging the app.

The problem is in request.POST.get("access_token")

request.POST = <QueryDict: {}> . I have no data in there

I am making a POST request in POSTMAN, where I added the data to body -> form-data. I also tried sending data through body->raw->json but anyway the request.POST does not contain anything.

enter image description here

What is the cause that I have no Post data? How can I get the POST data?

Thank you!

like image 801
Kate Cebotari Avatar asked Sep 07 '25 03:09

Kate Cebotari


1 Answers

Try using x-www-form-urlencoded instead of form data. x-www-form-urlencoded is the default form encoding for HTML forms.

Django does support enctype="multipart/form-data", which can be used for uploading files. So I'm afraid I can't explain why your request from Postman didn't work when you selected form data. Perhaps your request had an incorrect header.

like image 124
Alasdair Avatar answered Sep 10 '25 05:09

Alasdair