首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在/polls上找不到页面

在/polls上找不到页面
EN

Stack Overflow用户
提问于 2020-12-03 19:18:19
回答 2查看 78关注 0票数 0

我完全是" django“的初学者,所以我正在看一些教程,我正在看https://youtu.be/JT80XhYJdBw聪明的程序员教程,他正在看django的教程

在创建投票url之前,一切都很酷

Views.py代码:

代码语言:javascript
复制
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代码:

代码语言:javascript
复制
from django.urls import path

from . import views

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

Mypr\urls.py代码:

代码语言:javascript
复制
from django.contrib import admin

from django.urls import path, include

urlpatterns = [
    path('admin/',admin.site.urls),
    path('polls/',include('polls.urls')),
]

我不明白我做了同样的事情,但我得到的错误不仅仅是polls.In他决定做博客的一个透平,而且又是同样的错误:

代码语言:javascript
复制
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。

已经尝试过(但不起作用):

代码语言:javascript
复制
from django.urls import path

from polls.views import index

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

回答 2

Stack Overflow用户

发布于 2020-12-03 19:49:18

代码语言:javascript
复制
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页面。

票数 0
EN

Stack Overflow用户

发布于 2020-12-03 19:57:56

尝试在浏览器中访问polls/ url,然后才能访问页面,因为您已经访问了项目的URL,因此必须转到此URL才能访问应用程序

尝试像这样更改您的代码

代码语言:javascript
复制
from django.urls import path

from polls.views import index

urlpatterns = [
    path('', index, name='index'),
]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65124975

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档