django-URL之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')                
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM