【发布时间】:2020-02-17 23:27:13
【问题描述】:
我已经在我的 conda 环境中安装了 Django 2.2.5,我正在关注 Writing your first Django app, part 1 的 Django 教程
我完全按照这些步骤操作,但是当我尝试访问 polls/ url 时出现页面未找到错误。
我的根目录结构是这样的
mysite/
manage.py
db.sqlite3
urls.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
polls/
migrations/
__init__.py
admin.py
apps.py
models.py
tests.py
urls.py
views.py
而我的看法是这样的
D:\TEMP\djangotest\mysite\polls\views.py
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello World. You're at the polls index")
我的两个urls文件是这样的
D:\TEMP\djangotest\mysite\polls\urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
D:\TEMP\djangotest\mysite\urls.py
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('polls/', include('polls.urls')),
path('admin/', admin.site.urls),
]
我从这样的环境中运行应用程序
(py3.6) D:\TEMP\djangotest\mysite>python manage.py runserver
但是当我转到教程中指示的 url 时,它会给出 404 错误 - 从控制台找不到页面
October 21, 2019 - 16:23:13
Django version 2.2.5, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Not Found: /polls
[21/Oct/2019 16:23:19] "GET /polls HTTP/1.1" 404 1954
从浏览器看是这样的
Page not found (404)
Request Method:
GET
Request URL:
http://localhost:8000/polls
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
admin/
The current path, polls, 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.
【问题讨论】:
-
您是否将投票应用添加到您的项目 settings.py 文件中?
标签: django