Когда я нажимаю ссылку «выйти» на домашней странице (html страница), я получаю эту ошибку:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/login1/logout
Using the URLconf defined in webapp.urls, Django tried these URL patterns, in this order:
admin/
Home/ [name='Home']
login/ [name='login']
Signup/ [name='Signup']
login1/ [name='login1']
logout/ [name='logout']
The current path, login1/logout, didn't match any of these.
Я не понимаю, почему не удается найти функцию «выхода» в файле views.py.
Это Home. html
<body>
<center>
<h1 style="color:white">Welcome to my web page</h1>
<a href= 'logout' target="_blank">LogOut</a>
</center>
</body>
Это urls.py:
from django.contrib import admin
from django.urls import path
from application import views
urlpatterns = [
path('admin/', admin.site.urls),
path('Home/', views.Home , name = "Home"),
path('login/', views.login,name = 'login'),
path('Signup/', views.Signup , name = 'Signup'),
path('login1/',views.login1,name='login1'),
path('logout/',views.logout,name='logout'),
]
Это views.py:
from django.contrib import auth
from django.contrib.auth.models import User
from django.shortcuts import render, redirect
def login(request):
return render(request, 'login.html')
def login1(request):
if request.method == "POST":
uname = request.POST['username']
pwd = request.POST['pass']
user = auth.authenticate(username=uname, password=pwd)
if user is not None:
auth.login(request, user)
return render(request, 'Home.html')
else:
return render(request, 'login.html', {'error': 'invalid credential details'})
else:
return render(request, 'Signup.html')
def logout(request):
auth.logout(request) # logout is predefined
return redirect('/login/')