How do you access the HTTP data in a view derived from the generic View class?

26 views
Skip to first unread message

Daniel Grace

unread,
Aug 20, 2015, 3:58:28 PM8/20/15
to Django users
Suppose I have a view as follows:

from django.views.generic import View
from django.http import HttpResponse
from braces.views import CsrfExemptMixin

class TestView(CsrfExemptMixin, View):
    def post(self, request, *args, **kwargs):
        # how to access the HTTP data here?
        return HttpResponse(content='some response', status=200)

... and I want to access the data "12345" and "abcde" as in the command:
curl -X POST http://localhost:8000/test/ -d "foo=12345&bar=abcde"

Daniel Grace

unread,
Aug 20, 2015, 4:07:34 PM8/20/15
to Django users
I found the answer to this is to look at request.POST.

Luis Zárate

unread,
Aug 20, 2015, 4:09:49 PM8/20/15
to django...@googlegroups.com
with request.POST.get("foo", "") or request.POST.getlist("foo", [] )


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2ee2e83b-c240-492a-96f8-e3781e269710%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
"La utopía sirve para caminar" Fernando Birri


Reply all
Reply to author
Forward
0 new messages