django-include函数

Posted xiximayou

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了django-include函数相关的知识,希望对你有一定的参考价值。

三种格式:
(1)incude(module,namespace=None)

from django.urls import path,include
from book import urls
urlpatterns={
  path(‘‘,include(urls))                
}

module:模型文件,namespace:实例命名空间

(2)include(pattern_list)

from django.urls import path,include
from . import views
extractpatterns={
  path(‘‘,views.index,name=index) ,
  path(index/,views.index,name=index),   
  path(‘‘home/,views.index,name=index), 
}
urlpatterns={
  path(index/,include(extracpatterns),name=index)                
}

pattern_list:可迭代的path()或re_path()清单

(3)include((pattern_list,app_namespace),namespace)

app_namespace:app命名空间

from django.urls import path,include
from . import views
extractpatterns={
  path(‘‘,views.index,name=index) ,
  path(index/,views.index,name=index)   
  path(‘‘home/,views.index,name=index) 
}
urlpatterns={
  path(index/,include((extracpatterns,newsapp)),name=index)                
}

 

以上是关于django-include函数的主要内容,如果未能解决你的问题,请参考以下文章