标签:base return color col 前端 span 技术分享 admin reverse
#根据名称反向生成url from django.conf.urls import url,include from django.contrib import admin from django.shortcuts import HttpResponse,redirect from app01 import urls from niubin.service import v1 def index(request): from django.urls import reverse #根据名称反向生成url # test_url = reverse(‘xx‘) #反向生成url没参数 # test_url = reverse(‘xx‘,args=(2,9)) #反向生成url有参数 test_url = reverse(‘xx‘,kwargs={‘a2‘:2,‘a1‘:9}) #反向生成url命名参数 print(test_url) return HttpResponse(‘index‘) def test(request): return HttpResponse(‘test‘) urlpatterns = [ url(r‘^index/‘, index), url(r‘^test/asdf/asdf/asf/asdf/asf‘, test,name=‘xx‘), url(r‘^test/asdf/(\d+)/asf/(\d+)/asf‘, test,name=‘xx‘), url(r‘^test/asdf/(?P<a1>\d+)/asf/(?P<a2>\d+)/asf‘, test,name=‘xx‘), url(r‘nb/‘, v1.site.urls),]
{% extends ‘admin/base_site.html‘ %}
{% load il8n admin_urls static admin_list %}
{% block extrastyle %}
{% url ‘xx‘ %} #前端使用反向生成url
{% url ‘xx‘ 2 9 %} #有参数
{% url ‘xx‘ a1=2 a2=9 %} #有名字
{% endblock %}
标签:base return color col 前端 span 技术分享 admin reverse
原文地址:http://www.cnblogs.com/hsddon/p/7718709.html