我是“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/