我无法链接到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
答案 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')),
]