Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Django request.REQUEST.get() contain BOTH GET and POST parameters?

Are the parameters in request.POST and request.GET BOTH in request.REQUEST ? Or i have to check for each of them ?

I can't find a clear info in the documentation for both REQUEST/QueryDict. NB: Django 1.4 Final

like image 549
e-nouri Avatar asked Nov 14 '13 17:11

e-nouri


2 Answers

No, this was possible in older versions but was depreciated in Django 1.7. For Django archeologists running ancient versions, keep reading.

From the documentation:

HttpRequest.REQUEST

For convenience, a dictionary-like object that searches POST first, then GET. Inspired by PHP’s $_REQUEST.

For example, if GET = {"name": "john"} and POST = {"age": '34'}, REQUEST["name"] would be "john", and REQUEST["age"] would be "34".

It’s strongly suggested that you use GET and POST instead of REQUEST, because the former are more explicit.

like image 95
GrantJ Avatar answered Sep 28 '22 02:09

GrantJ


If you're not sure which you need to use, if can be handy to replace with this :

def get_post_or_get(request):
    """
    Return the equivalent of request.REQUEST 
    which has been removed in Django 1.9
    """
    return request.POST or request.GET

reference : https://github.com/edx/django-openid-auth/pull/5/commits/aa5eef791cd487eb359db25011572d5966a2c92a

like image 35
Albyorix Avatar answered Sep 28 '22 04:09

Albyorix