I try this routine, use curl to send a post to server, and want it to return http body.
Command:
curl --data "hi server" http://127.0.0.1:8000/verification/activate/
Server Side:
def activate(request):
if request.method == 'POST':
return HttpResponse(request.body)
else:
return HttpResponse('please send a post http.')
The string, "hi server", should be return message. but I got this error:
[18/Aug/2015 03:16:34]"POST /verification/activate/ HTTP/1.1" 403 2629
The CSRF middleware is activated by default in the MIDDLEWARE_CLASSES setting. This middleware returns HTTP 403 in case the csrf token is missing in request body.
You can either remove django.middleware.csrf.CsrfViewMiddleware from MIDDLEWARE_CLASSES array in settings.py or use csrf_exempt() decorator to disable csrf protection just for a single view:
(Please note that the first option is strongly discouraged for security measures)
from django.views.decorators.csrf import csrf_exempt
@csrf_exempt
def activate(request):
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With