скрипта?
Например есть скрипт "main.py"
import requests
SERVER = "http://127.0.0.1:8000/test/"
user = "User"
message = 'Trallalal lalal'
r = requests.post(SERVER, data={'user': user, 'message': message})
print(r.status_code, r.reason)
И django view
class Hello(TemplateView):
template_name = "test.html"
def get(self, request):
return self.render_to_response({})
@csrf_exempt
def post(self, request):
if request.method == 'POST':
user = request.POST['user']
message = request.POST['message']
Выдает ошибку:
Forbidden (CSRF cookie not set.): /test/
[27/Aug/2018 22:08:13] "POST /test/ HTTP/1.1" 403 3523
Заранее спасибо!
from django.utils.decorators import method_decorator from django.views.decorators.csrf import csrf_exempt class Hello(TemplateView): template_name = "test.html" @method_decorator(csrf_exempt) def dispatch(self, request, *args, **kwargs): return super(Hello, self).dispatch(request, *args, **kwargs) def post(self, request, **kwargs): user = request.POST.get('user') message = request.POST.get('message') return 'OK'
@method_decorator(csrf_exempt, name='dispatch') class Hello(TemplateView): ...
Обсуждают сегодня