代码如下:1#coding:utf823fromdjango.conf.urls.defaultsimportpatterns,url45fromviews.informationimportinformation6fromviews.long_relatedimportlong_related7fromviews.relatedimportrelated89urlpatterns=[]10urlpatterns+=patterns(11'',#这个空字符串的作用是什么?12url(r'^video/app/article/information/$',information,{'version':17}),13url(r'^video/app/article/information/v(?P\d+)/$',information),14url(r'^test/information/v(?P\d+)/$',information),15)1617urlpatterns+=patterns(#为什么要另外定义一个patterns加到urlpatterns中?18'',19url(r'^video/app/article/related/$',related,{'version':1}),20url(r'^video/app/article/related/v(?P\d+)/$',related),21)2223urlpatterns+=patterns(24'',25url(r'^video/app/article/related/long/$',long_related,{'version':1}),26)问题也如代码中的注释,首先为什么要append三个patterns,合在一起不行吗?比如9urlpatterns=[]10urlpatterns+=patterns(11'',#这个空字符串的作用是什么?12url(r'^video/app/article/information/$',information,{'version':17}),13url(r'^video/app/article/information/v(?P\d+)/$',information),14url(r'^test/information/v(?P\d+)/$',information),19url(r'^video/app/article/related/$',related,{'version':1}),20url(r'^video/app/article/related/v(?P\d+)/$',related),25url(r'^video/app/article/related/long/$',long_related,{'version':1}),26)另外,patterns里面有一个空字符串‘’,这是干什么的呢?
2 回答
繁星coding
TA贡献1797条经验 获得超4个赞
1、为什么要append三个pattern为了可读性和可维护性,通常会把相同功能或相似url的放到一组里面这是不同人的不同写法,当然可以所有的都写到一起2、patterns里面有一个空字符串‘’,这是干什么的呢patterns(prefix,*args)方法的第一个参数
添加回答
举报
0/150
提交
取消