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

 

 

 

 

posted @ 2021-07-02 17:28  半日闲1  阅读(100)  评论(0编辑  收藏  举报