python - 在/polls找不到页面

标签 python django error-handling pycharm

我是“django”的初学者,所以我正在关注一些教程,而我正在看https://youtu.be/JT80XhYJdBw Clever Programmer的教程,他遵循django教程
一切都很不错,直到进行民意调查网址
views.py代码:

from django.shortcuts import render

from django.http import HttpResponse

def index(request):
    HttpResponse("Hello World.You're at the polls index")
民意测验\ urls.py的代码:
from django.urls import path

from . import views

urlpatterns = [
    path('', views.index, name='index'),
]
Mypr \ urls.py的代码:
from django.contrib import admin

from django.urls import path, include

urlpatterns = [
    path('admin/',admin.site.urls),
    path('polls/',include('polls.urls')),
]
我不明白,我做了同样的事情,但不仅是民意测验我也遇到了错误。
Page not found (404)
Request Method: GET
Request URL:    http://127.0.0.1:8000/polls/
Using the URLconf defined in Mypr.urls, Django tried these URL patterns, in 
this order:

admin/
The current path, polls/, didn't match any of these.
请我的前辈帮我。
注意:我使用的是django,windows的最新版本,并且作为编辑器,我使用的是Pycharm。
已经尝试过(并且不起作用):
from django.urls import path

from polls.views import index

urlpatterns = [
    path('', index, name='index'),
]

最佳答案

Page not found (404)
Request Method: GET
Request URL:    http://127.0.0.1:8000/polls/
Using the URLconf defined in Mypr.urls, Django tried these URL patterns, in this order:

admin/
The current path, polls/, didn't match any of these.
您看到此错误是因为Django设置文件中包含DEBUG = True
将其更改为False,Django将显示一个标准的404页面。

关于python - 在/polls找不到页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65124975/

相关文章:

r - 在循环中检测错误

python - 类型错误 : 'float' object has no attribute '__getitem__'

python - Python 的 pip 是否有像 npm/package.json 这样的项目文件支持?

python - 根据条件委托(delegate)排序

django - "yum install django"会覆盖现有的 django 版本吗

java - 如何在线程 “main”中修复异常java.util.InputMismatchException

python - 尝试在 Python 3 中将时间转换为整数

python - Django 将模型 ID 添加到 URL

python - django-rest-swagger 不能很好地与模型序列化器一起使用吗?

c++ - std::cin 不会在输入错误时抛出异常