1) The content-length of your request (in your previous email) is 0, suggesting there was no body submitted with the request. What is the CURL command you're using to make the request?
2) HttpRequest.body should be request.body. HttpRequest is a class not the request object (which is an instance of HttpRequest), so HttpRequest.body isn't going to give you anything useful.
_Nik
On 7/2/2013 2:51 PM, Lucas Simon wrote:
Also, here is my updated view
--from django.http import HttpResponse, HttpRequest , Http404from django.views.generic.base import Viewfrom django.views.decorators.csrf import csrf_exempt
class TestView(View):def post(self, request, *args, **kwargs):print "*******************************"print HttpRequest.bodyprint request.bodyprint "*******************************"return HttpResponse("hello, world")
which returns
*******************************<property object at 0x1fd05d0>
*******************************[02/Jul/2013 15:51:07] "POST /blog/ HTTP/1.1" 200 12
On Tuesday, July 2, 2013 3:34:47 PM UTC-6, Nikolas Stevenson-Molnar wrote:Are you sending the JSON document as the body of your POST request? If so, you won't see anything in request.POST, because it's only populated for requests using application/x-www-form-urlencoded. You probably want to use request.body (https://docs.djangoproject. com/en/1.5/ref/request- ) to get at the raw JSON. To get it as a dictionary object in Python, import the json module, then do:response/#django.http. HttpRequest.body
>>> data = json.loads(request.body)
_Nik
On 7/2/2013 2:28 PM, Lucas Simon wrote:
How does this fit in with a large JSON document? There should be a way to parse all of this arbitrary data, and filter out the stuff that fits into a form
On Tuesday, July 2, 2013 3:08:10 PM UTC-6, Nikolas Stevenson-Molnar wrote:--That's the expected output, since your URL pattern to that view doesn't contain any arguments. Take a look at the examples in https://docs.djangoproject.com/en/1.5/topics/http/urls/ ... the URL patterns with groups will have the matched values passed to the view function as arguments (named groups are passed as kwargs).
Likewise, unless you submitted POST data with your request, you should expect request.POST to be empty.
_Nik
On 7/2/2013 2:03 PM, Lucas Simon wrote:
Hi,
I think I found a bug and was not sure where to post it other than here. I have created a view defined as follows
from django.http import HttpResponse, Http404from django.views.generic.base import View
class TestView(View):def post(self, request, *args, **kwargs):print "*******************************" print request.POSTprint argsprint kwargsprint "*******************************" return HttpResponse("hello, world")
When I make a post request with CURL or advanced rest framework, the console outputs blank data,
******************************* <QueryDict: {}>(){}******************************* [02/Jul/2013 15:00:39] "POST /blog/ HTTP/1.1" 200 12
Also, it is probably worth mentioning that I commented out the csrf middleware. My two urls.py files are define as
from django.conf.urls import patterns, include, url
# Uncomment the next two lines to enable the admin:# from django.contrib import admin# admin.autodiscover()
urlpatterns = patterns('',url(r'^blog/', include('blog.urls')),# Uncomment the admin/doc line below to enable admin documentation:# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:# url(r'^admin/', include(admin.site.urls)),)
and as follows for blog.urls.py
--from django.conf.urls import patterns, include, urlfrom .views import *
urlpatterns = patterns('',url(r'^$', TestView.as_view()),)
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 .
For more options, visit https://groups.google.com/groups/opt_out .
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 .
For more options, visit https://groups.google.com/groups/opt_out .
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment