problem with requests and django view

33 views
Skip to first unread message

ogi

unread,
May 29, 2015, 11:09:39 AM5/29/15
to django...@googlegroups.com
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



ogi

unread,
May 31, 2015, 2:53:56 PM5/31/15
to django...@googlegroups.com
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.
Reply all
Reply to author
Forward
0 new messages