错误:无法路由到我新创建的应用程序

时间:2019-11-28 05:43:13

标签: python django

所以我正在关注https://docs.djangoproject.com/en/2.2/topics/http/urls/上的django教程 我到达应该可以导航到民意调查网址的位置,而我却收到404错误

[
    {
        "name" : "john"
    },
    {
        "name" : "oliver"
    },
    {
        "name" : "florence"
    }
]

我的文件夹结构是

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.

我已将mysite / urls.py修改为

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

在民意调查文件夹中添加了一个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 / views.py文件调整为

from django.urls import path

from . import views

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

管理页面运行正常,但我无法导航至http://localhost:8000/polls/。 我用不同的名称尝试了几次,但没有成功。请帮助。谢谢

1 个答案:

答案 0 :(得分:0)

现在正在工作。我认为我对文件所做的更改之前没有保存过。重新启动atom并保存所有文件后,它现在可以工作了。谢谢您的帮助。