django drf login template

2019-09-15 07:57发布

问题:

I extend the login template of DRF

{% extends "rest_framework/login_base.html" %}
{% block branding %}
  <h3 style="margin: 0 0 20px;">My site</h3>
{% endblock %}

with urls.py:

urlpatterns = [
    url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
    url(r'^login', login, template_name, name='login'),
    url(r'^logout', logout, template_name, name='logout'),
...

Everything works well except if the connection fails: DRF redirect to http://127.0.0.1:8000/api-auth/login/ instead of http://127.0.0.1:8000/login/ and my extended template is not used. So I lose my site name for "Django REST framework" title.

Regards

回答1:

Put the template in templates/rest_framework/ and

urlpatterns = [
    url(r'^auth/', include('rest_framework.urls', namespace='rest_framework')),