动态构建 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:
False: