Answer the question
In order to leave comments, you need to log in
How to exchange csrf token with frontend?
There is a frontend in angular and a backend in django2.2.2. The frontend consists of one page, which has a registration form. I would like to sign it with a csrf token, send it and check for the presence of a token on the server side.
Here is what I tried to do to implement this
view idea:
from django.shortcuts import render
from django.contrib.auth.models import User
from django.http import JsonResponse
from django.views.decorators.csrf import ensure_csrf_cookie
@ensure_csrf_cookie
def get_csrf(request):
response = JsonResponse([{"cookie_set": True}], safe=False)
return response
def registration(request):
# some payload
response = JsonResponse([{"registration_successful": True}], safe=False)
return response
127.0.0.1:8000/app_auth/get_csrf
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question