Answer the question
In order to leave comments, you need to log in
Remote authorization REST API how to implement?
There is a server on Django REST API
There is a web application on normal Django.
Those. the connection is made: Django REST API Server
<=>
Django app <=>
Client
<form action="{% url 'todolist:login' %}" method="post">
{% csrf_token %}
{{ form }}
<input type="submit" value="Login" />
</form>
class LoginView(View):
@method_decorator(csrf_exempt)
def get(self, request, *args, **kwargs):
form = LoginForm()
return render(request, 'login.html', {'form': form})
@method_decorator(csrf_exempt)
def post(self, request, *args, **kwargs):
form = LoginForm(request.POST)
if form.is_valid():
post_data = {'username': form.cleaned_data['username'], 'password': form.cleaned_data['password']}
response = requests.post('http://127.0.0.1:8080/api-auth/login/', data=post_data)
return HttpResponseRedirect('/todolists/')
Answer the question
In order to leave comments, you need to log in
On the django-rest server side, there is csrf protection. It is necessary at the time of calling requests.post (call for) to throw csrf token into cookies (it can be obtained from the current request)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question