我完全是" django“的初学者,所以我正在看一些教程,我正在看https://youtu.be/JT80XhYJdBw聪明的程序员教程,他正在看django的教程
在创建投票url之前,一切都很酷
Views.py代码:
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
HttpResponse("Hello World.You're at the polls index")Polls\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')),
]我不明白我做了同样的事情,但我得到的错误不仅仅是polls.In他决定做博客的一个透平,而且又是同样的错误:
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'),
]发布于 2020-12-03 19:49:18
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页面。
发布于 2020-12-03 19:57:56
尝试在浏览器中访问polls/ url,然后才能访问页面,因为您已经访问了项目的URL,因此必须转到此URL才能访问应用程序
尝试像这样更改您的代码
from django.urls import path
from polls.views import index
urlpatterns = [
path('', index, name='index'),
]https://stackoverflow.com/questions/65124975
复制相似问题