I found myself the solution. Stupid!. The variable url was entered without slash at the end.
Anyway thanks to all. Maybe somebody could see that if I copied the url and urls.py in the question.
Am Freitag, 29. Mai 2015 17:09:39 UTC+2 schrieb ogi:
-- Anyway thanks to all. Maybe somebody could see that if I copied the url and urls.py in the question.
Am Freitag, 29. Mai 2015 17:09:39 UTC+2 schrieb ogi:
Hi
I have problems to post some json data from a python script using requests to a django view defined as base classed view.
Thinking that problem is with permissions I also installed django rest framework to temporary allow any user to call the view.
the file with post data is looking like:
data = {'k1': 'val1', 'k2': 'val2'}
jdata = json.dumps(data)
r = requests.post(url, data=jdata, headers=headers)
print r
and the correspondign class based view registrated in urls.py:
class LoadData(APIView):
"""
A view that can accept POST requests with JSON content.
"""
parser_classes = (JSONParser,)
permission_classes = (AllowAny,)
def post(self, request, format=None):
# pdb.set_trace()
now the method post will be not executed.
When I use put method instead of post the situation is better but also without data
in request.data or args, kwargs.
I used many times jQuery with ajax and post method in similar cases and it was always working,
so I have no idea what is the difference and what I am missing.
Any hint will be very appreciated and thanks in advance.
Ogi
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/019e4712-c1a4-4c8b-9a2f-0dead5c9b34e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment