使用app_name
with include
在Django 1.9中已弃用,在Django 2.0中不起作用。设置app_name
在blog/urls.py
代替。
app_name = 'blog'
urlpatterns = [
url(r'^$', views.post_list, name='post_list'),
...
]
然后将include更改为:
url(r'^blog/', include('blog.urls')),
您不需要namespace='blog'
,因为它将默认为应用程序命名空间。
'Specifying a namespace in include() without providing an app_name '
APP url
# app_name="blog"
urlpatterns = [
url(r"^$",views.blog_title,name="blog_title"),
]
include() got an unexpected keyword argument 'app_name'
项目 URL
urlpatterns = [
path('admin/', admin.site.urls),
url(r"^blog/",include('blog.urls',namespace='blog',app_name="blog")),
]
项目URL
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('admin/', admin.site.urls),
path(r'blog/', include('blog.urls')),//use this
]