python - 如何修复 django 中的 Page Not Found (404) 错误
问题描述
如何在 django 3.0 中修复此错误,当我尝试使用表单发布方法访问页面时,我收到此错误
嗨,我是 Django 编程语言的新手,现在我正在用 django 开发一个大学项目,当我使用表单在POST方法中创建登录时。如果我把它放在主页上,它工作得很好。但是当我将表单放入另一个页面(about.html)时,我收到了这个错误。我无法修复它。所以大家请帮帮我..
> Page not found (404) Request Method: POST Request
> URL: http://127.0.0.1:8000/about/login Using the URLconf defined in
> mysite.urls, Django tried these URL patterns, in this order:
>
> [name='home'] login/ about/ admin/ The current path, about/login,
> didn't match any of these.
>
> You're seeing this error because you have DEBUG = True in your Django
> settings file. Change that to False, and Django will display a
> standard 404 page.
应用程序/ Urls.py
from django.urls import path
from . import views
urlpatterns = [
path('',views.home,name='home'),
path('', views.about, name="about"),
path('', views.login, name="login")
path('admin/', admin.site.urls),
]
项目/ urls.py
from django.contrib import admin
from django.urls import path,include
from pages.views import home, about, login
urlpatterns = [
path('',home,name='home'),
path('login/',login),
path('about/',about),
path('admin/', admin.site.urls),
]
视图.py
from django.shortcuts import render, redirect
from django.http import HttpResponse
# Create your views here.
def home(request, *args, **kwargs):
return render(request, "test.html")
def about(request,*args, **kwargs):
return render(request,"inner.html")
def login(request, *args, **kwargs):
return render(request, "result.html")
HTML 表格
<form action="login" method="POST">
{% csrf_token %}
<label> username</label>
<input type="text" name="uname"><br>
<label> Password</label>
<input type="Password" name="upwd"><br>
<input type="submit" name="submit" value="submit">
</form>
解决方案
action="login"
你在第一次写的主要问题是action="/login"
为了解决你的问题,因为现在你添加login
到当前打开的 url
推荐阅读
- java - 无法使用 xpath 单击元素
- angular - NPM:checkPermissions 缺少对 | 的写访问权限 离子 4 和 Angular 8
- eloquent - 在 laravel 中使用带有 javascript 的资源控制器从数据库中获取数据
- javascript - Micobit 仅在事件中向计算机发送串行数据?
- java - 如何使用 Azure 函数将值插入 AzureSQL 数据库
- python - 六角格子
- azure - 如何将 Google IDP 与 Azure 广告 b2c 登录用户流集成?
- php - 如何计算多维数组中的特定键值?
- android - 拍照时有没有办法调用方法
- php - Drupal 将模块的功能覆盖到另一个模块的功能中,复制表单