其他分享
首页 > 其他分享> > 动态构建 urlpatterns

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

 

 

 

 

标签:views,url,settings,构建,urlpatterns,test,import,动态
来源: https://www.cnblogs.com/yu121/p/14964221.html