将应用程序urls.py链接到项目的urls.py时出现“未找到:/”错误

时间:2019-04-03 05:10:43

标签: python django

我无法链接到Django中应用程序的urls.py文件

first_project urls.py

from django.contrib import admin
from django.urls import path
from django.conf.urls import include

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

first_app urls.py

from django.conf.urls import url
from first_app import views

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

错误

Django version 2.1.7, using settings 'first_project.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Not Found: /
[31/Mar/2019 14:28:54] "GET / HTTP/1.1" 404 2038

2 个答案:

答案 0 :(得分:1)

根据您的 URL配置 ,您应该访问以下网址, /first_app/

例如:http://localhost/first_app/

答案 1 :(得分:1)

您必须在first_app网址中添加斜杠:

from django.contrib import admin
from django.urls import path
from django.conf.urls import include

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