动态构建 urlpatterns

urls:

from django.conf import settings
from django.conf.urls import url

from myApp import views

urlpatterns = [
    url(r"^index/$", views.fun),

]

if settings.DEBUG:
    urlpatterns += [url(r'^debuginfo/$', views.test_debug),]

if settings.BRX:
    urlpatterns += [url(r'^brxinfo/$', views.test_brx),]

views:

def test_debug(request):
    return HttpResponse("debuginfo......")

def test_brx(request):
    return HttpResponse("brxinfo......")

True:

动态构建 urlpatterns

 

 

 False:

 

 

 动态构建 urlpatterns

 

上一篇:DevExpress GridControl实现奇偶行变色及整行选中实现


下一篇:路由嵌套