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.
What is the cause that I have no Post data? How can I get the POST data?
Thank you!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With