Hi guys hope someone can help me here. I am just starting to create a simple web app using django and I am confused why this isn't working.
views.py
from django.shortcuts import render, redirect
from django.contrib.auth import login, logout
def index(request):
return render(request, "fittracker/main.html")
def login_view(request):
pass
def logout_view(request):
logout(request)
return redirect("fittracker/main.html")
def signup(request):
pass
urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
path("logout/", views.logout, name='logout')
]
I have tired looking at the official docs, and this should redirect, but I am not sure why it isn't
The name of the view is logout_view
, so it hould be views.logout_view
:
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
path('logout/', views., name='logout')
]
Now you use the logout
that you re-exported from the django.contrib.auth
module.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.