Django18初体验


1410 浏览 5 years, 9 months

29 在导航条添加授权链接

版权声明: 转载请注明出处 http://www.codingsoho.com/

navbar.html

          <ul class="nav navbar-nav navbar-right">
          {% if request.user.is_authenticated %}
            <li><a href="{% url 'auth_logout' %}">Logout</a></li>
            {% else %}
            <li><a href="{% url 'registration_register' %}">Register</a></li>
            <li><a href="{% url 'auth_login' %}">Login</a></li>
            {% endif %}
          </ul>

registration_register is url name of register (django-registration-redux)

其他的名字都能在下面URL找到

urlpatterns = [
    url(r'^login/$',
        auth_views.login,
        {'template_name': 'registration/login.html'},
        name='auth_login'),
    url(r'^logout/$',
        auth_views.logout,
        {'template_name': 'registration/logout.html'},
        name='auth_logout'),
    url(r'^password/change/$',
        auth_views.password_change,
        {'post_change_redirect': reverse_lazy('auth_password_change_done')},
        name='auth_password_change'),
    url(r'^password/change/done/$',
        auth_views.password_change_done,
        name='auth_password_change_done'),
    url(r'^password/reset/$',
        auth_views.password_reset,
        {'post_reset_redirect': reverse_lazy('auth_password_reset_done')},
        name='auth_password_reset'),
    url(r'^password/reset/complete/$',
        auth_views.password_reset_complete,
        name='auth_password_reset_complete'),
    url(r'^password/reset/done/$',
        auth_views.password_reset_done,
        name='auth_password_reset_done'),
]