Sunday, May 31, 2015

Re: problem with requests and django view

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 in the question.

Am Freitag, 29. Mai 2015 17:09:39 UTC+2 schrieb ogi:

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 =, data=jdata, headers=headers)
print r

and the correspondign class based view registrated in

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 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.

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
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment