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

 

动态构建 urlpatterns

上一篇:docker部署django网站


下一篇:解决linux下 使用netcore生成图片报错的问题:The type initializer for 'Gdip' threw an exception