python - 错误:无法路由到我新创建的应用程序
问题描述
因此,我正在关注https://docs.djangoproject.com/en/2.2/topics/http/urls/上的 django 教程, 我已经到了应该能够导航到投票 url 的地步,但我得到了 404 错误
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.
我的文件夹结构是
D:.
| db.sqlite3
| manage.py
|
+---mysite
| | settings.py
| | urls.py
| | wsgi.py
| | __init__.py
| |
| \---__pycache__
| settings.cpython-37.pyc
| urls.cpython-37.pyc
| wsgi.cpython-37.pyc
| __init__.cpython-37.pyc
|
\---polls
| admin.py
| apps.py
| models.py
| tests.py
| urls.py
| views.py
| __init__.py
|
\---migrations
__init__.py
我已将 mysite/urls.py 修改为
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('polls/', include('polls.urls')),
path('admin/', admin.site.urls),
]
在 polls 文件夹中添加了一个 urls.py 文件并用
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index')
]
最后将 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")
管理页面工作正常,但我无法导航到http://localhost:8000/polls/。我用不同的名字尝试了几次,但没有成功。请帮助。谢谢
解决方案
它现在正在工作。我认为我对文件所做的更改之前没有保存。在我重新启动 atom 并保存所有文件后,它现在可以工作了。感谢您的帮助。
推荐阅读
- powershell - 通过 PowerShell 在 FtpWebRequest 期间永久接受证书
- java - 线程回调返回值
- sql - 如果值大于 SQL 中的先前值,则选择记录
- swift - Kotlin 是否有扩展类来像 Swift 一样接口
- php - 使用密码加密方案的 PHP 安全登录系统
- encoding - 不可映射的字符
- mapbox - Mapbox:如何计算图块大小和位置
- mongodb - 如何使用 docker-compose 通过 pymonogo 应用程序设置 mongodb?
- mongodb - Mongodb:聚合的结果不是预期的($lookup)
- sql-server - 与组外连接