找不到页面404 django-登录页面

时间:2020-08-15 11:09:59

标签: python-3.x django django-models django-views django-templates

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

我在下面发布了与此问题相关的urls.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>

1 个答案:

答案 0 :(得分:0)

urls.py 中添加主网址:

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