【发布时间】:2023-03-28 17:20:01
【问题描述】:
from django.http import HttpResponse
from django.shortcuts import render,redirect, get_list_or_404, get_object_or_404
from .models import Users
from .forms import UsersForm
from django.contrib.auth import authenticate
# Create your views here.
def login(request):
#Username = request.POST.get(‘username’)
#password = request.POST.get(‘password’)
form = UsersForm(request.POST or None)
if form.is_valid():
form.save()
form = UsersForm()
return redirect('/product/itemlist')
user = authenticate(username='username', password='password')
if user is not None:
# redirect to homepage
return redirect('/product/itemlist')
else:
# display login again
return render(request, 'users/login.html', {'form':form})
这是我运行服务器时的查看页面,它需要我登录页面,然后当我输入我的凭据并尝试登录时问题就开始了
找不到页面 (404) 请求方法:POST 请求 URL:http://127.0.0.1:8000/users/login/index.html 使用 URLconf 在 mazwefuneral.urls 中定义,Django 尝试了这些 URL 模式,在这个 顺序:
admin/product/users/login/[name='login'] main/accounts/
当前路径 users/login/index.html 与其中任何一个都不匹配。
您看到此错误是因为您的 Django 中有 DEBUG = True 设置文件。将其更改为 False,Django 将显示 标准 404 页面。
这是我遇到的错误
【问题讨论】:
-
请发布您的
urls.py:很可能需要更改render(request, 'users/login.html', {'form':form})以匹配相应的网址。 -
欢迎来到 Stack Overflow 并祝贺您提出了一个非常好的第一个问题!