Python 3.x 找不到404 django页面-登录页面

Python 3.x 找不到404 django页面-登录页面,python-3.x,django,django-models,django-views,django-templates,Python 3.x,Django,Django Models,Django Views,Django Templates,我正在尝试使用用户名和密码登录,单击登录按钮它应该重定向到homepage.html,但我得到页面未找到错误404。请帮帮我 我已经发布了与下面这个问题相关的url.py、views.py和html标记。如果你需要更多的细节,请告诉我 #urls.py from django.urls import path from . import views from django.contrib.auth import views as auth_view urlpatterns = [

我正在尝试使用用户名和密码登录,单击登录按钮它应该重定向到homepage.html,但我得到页面未找到错误404。请帮帮我

我已经发布了与下面这个问题相关的url.py、views.py和html标记。如果你需要更多的细节,请告诉我

#urls.py 

from django.urls import path
from . import views
from django.contrib.auth import views as auth_view

urlpatterns = [


    path('', views.login, name='login_page'),
    path('/login_validation/', views.login_validation, name="login_validation"),

    #path('login/', auth_view.LoginView.as_view(template_name='templates/login.html'), name='login'),
    #path('logout/', auth_view.LogoutView.as_view(template_name='templates/logout.html'), name='logout'),
]



#views.py


from django.shortcuts import render, redirect
from django.contrib.auth.models import User, auth
from django.contrib import messages

def login(request):
    return render(request, "login.html")

def login_validation(request):
    if request.method=='POST':
        username=request.POST("username")
        password=request.POST("password")
        user=auth.authenticate(username=username, password=password)

        if user is not None:
            auth.login(request, user)
            return render(request, "homepage.html")
        else:
            return render(request, "login.html")

    else:
        return render(request, "login.html")


login.html
    
 <div class="col-sm-12 controls">
 <center> <a id="btn-login" type ="submit" href="{% url 'login_validation' %}" class="btn btn-success">Login  </a></center>
    
 </div>
#url.py
从django.url导入路径
从…起导入视图
从django.contrib.auth导入视图作为auth_视图
URL模式=[
路径(“”,views.login,name='login_page'),
路径('/login\u validation/',views.login\u validation,name=“login\u validation”),
#路径('login/',auth_view.LoginView.as_view(template_name='templates/login.html'),name='login'),
#路径('logout/',auth_view.LogoutView.as_view(template_name='templates/logout.html'),name='logout'),
]
#views.py
从django.shortcuts导入渲染,重定向
从django.contrib.auth.models导入用户,auth
从django.contrib导入消息
def登录(请求):
返回呈现(请求“login.html”)
def登录验证(请求):
if request.method==“POST”:
用户名=request.POST(“用户名”)
密码=请求.发布(“密码”)
user=auth.authenticate(用户名=用户名,密码=密码)
如果用户不是无:
身份验证登录(请求、用户)
返回呈现(请求“homepage.html”)
其他:
返回呈现(请求“login.html”)
其他:
返回呈现(请求“login.html”)
login.html

url.py中添加主url

from django.views.generic.base import TemplateView
path('home', TemplateView.as_view(template_name='home.html'), name='home'),

您是否尝试过从路径('/login\u validation/',views.login\u validation,name=“login\u validation”)中删除斜杠,?是…但没有用他们现在至少我的代码已经连接上了..但是点击按钮后请求没有被发送我建议你使用此教程一定会检查它我得到了解决方案它与代码的其他部分有错误哪里有错误??