A
A
albertalexandrov2018-07-11 11:20:52
Django
albertalexandrov, 2018-07-11 11:20:52

Why can't django post request be sent without a form?

Hello!
django==1.11
There is a view:

class SimpleRoutingView(View):

    def get(self, request):
        print('Поступил get-запрос')
        return HttpResponse('Поступил get-запрос', status=200)

    def post(self, request):
        print('Поступил post-запрос')
        return HttpResponse('Поступил post-запрос', status=405)

    def put(self, request):
        return HttpResponse('Поступил put-запрос', status=405)

The built-in local Django server is running. Next, I make requests using the requests library.
The get request goes through normally and the message "Get request received" is printed in the console.
When I execute an empty, formless post request with no data: requests.post(url), I get the standard 403 error. But you need to return the 405th status (on assignment).
5b45c43eef9fd434786999.jpeg
How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem, 2018-07-11
@albertalexandrov

no mb token

from django.views.decorators.csrf import csrf_exempt
...
url(r'^admin/', csrf_exempt(SimpleRoutingView.as_view())),

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question