I’m trying to send a POST request from iPhone to Django, but for some reason I can’t. The request is sent, but the server doesn’t receive it properly.
- What is the regular expression that accepts POST? In my case, I use this one:
/messages/a/s=person1&r=person2&c=hello/. - How do I retrieve the POST arguments in the Django view?
request.POST['s']should work?
Thanks.
POST parameters are not part of the URL, so your regex should simply detail the main part of the url you want to receive it on. To take your example, change it to
/messages/a/. Then, in your “messages” app, have a view/function calleda: that one will be reached on receiving any POST (or GET, which you’re currently (almost) depicting in your url) to that location.The arguments can then indeed be retrieved using
request.POST['keyname']. To make things more convenient, supply a default value when getting the data so you need less error checking:request.POST.get('keyname', None). This will get the value ofkeynamewhen available, orNoneotherwise.The posting itself… depends on more code then you’re currently showing. Can’t say anything about that with your current question.