当前位置: 代码迷 >> 综合 >> django.urls include 请求不到子APP路径 问题
  详细解决方案

django.urls include 请求不到子APP路径 问题

热度:43   发布时间:2023-11-26 09:12:27.0

1.项目 url

from django.contrib import admin
from django.conf.urls import url
from django.urls import include
urlpatterns = [url('admin/', admin.site.urls),url(r'', include('book.urls')),
]

2.book APP的url 

from django.contrib import admin
from django.conf.urls import url
from book import views
from django.urls import includeurlpatterns = [url('admin/', admin.site.urls),# url(r'^index$', include('book.urls')),url('index', views.index),  #和视图函数做请求url('create', views.create),  #和视图函数做请求url('addAjax', views.addAjax),  #和视图函数做请求url('getAll', views.getAll),  #和视图函数做请求url(r'^delete(\d+)$', views.dele),  #和视图函数做请求
]

3.出错就在项目url(r'^index$', include('book.urls')),用这导致路径请求不到,,而需要用 url(r'', include('book.urls')),

  相关解决方案