0

my urls.py setting is

path('somepath', views.somefunc.as_view(), name='SomeFunc')

SomeFunc takes POST and is supposed to take some query commands like

localhost:8000/path/to/somepath?a=f&b=g

When I print out the request itself, it seems like it's only reading POST /path/to/somepath?a=f and I cannot get anything from request.POST

How do I read both a and b?

This is Django2.0 by the way

EDIT:

I feel like I have some misunderstanding of the fundamental of django or even REST in general.

When I try to do a requests.post in python as I pass in the queries in the url, somehow those queries show up in request.GET on the django side.

My understanding has been that requests.post posts the data set in queries to django, so the queryset should show up in POST instead of GET

This seems like it's not the case. I wonder what I'm missing here.

using request.GET fixes everything..... but it's not really a fix so to speak

1
  • 1
    Well yes, you have understood REST - or actually HTTP. A POST contains its data in the body, not in the URL. If for example you did requests.post('localhost:8000/path/to/somepath', {'a': 'f', 'b': 'g'}), that dict would be sent as the body in form-encoded format and received in request.POST. Commented Jun 30, 2018 at 8:00

1 Answer 1

1

That's not POST data, it's GET. You can get it from request.GET.

Sign up to request clarification or add additional context in comments.

3 Comments

i'm doing curl -XPOST localhost:8000/path/to/somepath?a=f&b=g does it change anything?
I tried printing out request.GET even when i'm using POST and I got something, still I'm missing the second query. Seems like now i have two problems to solve
Looks like using requests package can make me get both queries, but somehow it's still a GET.....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.