Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Example when request.POST contain query string in django

Please post example code when request.POST contain query string in django, because i think my django version is bugged.

EDIT:

You simple can't, query string is always in GET, and this was my problem.

like image 884
SuitUp Avatar asked Jun 02 '10 20:06

SuitUp


People also ask

Can we use query string in POST method?

A POST request can include a query string, however normally it doesn't - a standard HTML form with a POST action will not normally include a query string for example.

CAN POST request have query parameters?

POST should not have query param. You can implement the service to honor the query param, but this is against REST spec. "Why do you pass it in a query param?" Because, like for GET requests, the query parameters are used to refer to an existing resource.

What is query string in post request?

A query string commonly includes fields added to a base URL by a Web browser or other client application, for example as part of an HTML, choosing the appearance of a page, or jumping to positions in multimedia content.

How does Django treat a request URL string?

Django runs through each URL pattern, in order, and stops at the first one that matches the requested URL, matching against path_info . Once one of the URL patterns matches, Django imports and calls the given view, which is a Python function (or a class-based view).


1 Answers

If your request is post:

request.method == 'POST'

but the requested url contains a query string. e.g:

/your-url?param1=value-one

you can still take POST parameters through:

request.POST.get("my-field", None)

and query string parameters through:

request.GET.get("param1")

althrough, you pick up all parameters at once (POST and GET), through REQUEST:

request.REQUEST['param1'] # comes from query string

request.REQUEST['my-field'] # comes from request BODY (POST)

like image 136
Gabriel Falcão Avatar answered Sep 20 '22 14:09

Gabriel Falcão