标签:register turn cut shortcut eve response end regex reverse
1 from django.urls import path,register_converter 2 from app01 import views 3 4 class MyCon: 5 regex=‘[0-9]{4}‘ 6 def to_python(self,value): 7 return int(value) 8 def to_url(self,value): 9 return ‘%04d‘ % value 10 11 register_converter(MyCon,‘aa‘) 12 13 urlpatterns = [ 14 path(‘admin/‘, admin.site.urls), 15 path(‘test/<aa:year>‘, views.test,name=‘test‘), 16 ]
1 from django.shortcuts import render,HttpResponse,reverse 2 3 4 def test(request,year): 5 print(year) 6 print(type(year)) 7 url=reverse(‘test‘,args=(5,)) 8 print(url) 9 return HttpResponse(‘ok‘)
标签:register turn cut shortcut eve response end regex reverse
原文地址:https://www.cnblogs.com/xuqidong/p/12252644.html