python - How to logout in django? -
html code
{% if request.user %} <a href="{% url 'main:logout' %}"> Выход </a> {% else %} <a href="{% url 'main:registration' %}"> Регистрация </a> {% endif%}
settings.py
login_redirect_url = 'main/index'
views.py
def logout(request): logout(request)
urls.py
from django.conf.urls import url . import views django.conf import settings urlpatterns = [ url(r'^logout/$', views.logout, {'next_page': settings.logout_redirect_url}, name='logout') ]
what's wrong?
you using custom logout view doesn't take next_page parameter. should add parameter view , pass django logout call, or use django.contrib.auth.logout
e.g. in urls.py:
from django.conf.urls import url django.conf import settings django.contrib.auth.views import logout urlpatterns = [ url(r'^logout/$', logout, {'next_page': settings.logout_redirect_url}, name='logout') ]
Comments
Post a Comment