首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >django-URL之include函数(五)

django-URL之include函数(五)

作者头像
西西嘛呦
发布于 2020-08-26 10:21:14
发布于 2020-08-26 10:21:14
7310
举报

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

代码语言:javascript
复制
from django.urls import path,include
from book import urls
urlpatterns={
  path('',include(urls))                
}

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

(2)include(pattern_list)

代码语言:javascript
复制
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命名空间

代码语言:javascript
复制
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')                
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019-10-24 ,如有侵权请联系 cloudcommunity@tencent.com 删除
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档