python - django中Passing extra options to view functions的描述不是太明白,求指教
黄舟
黄舟 2017-04-18 09:51:29
0
1
408

urls.py

url('^blog/(?P[0-9]{4})/$', views.year_archive,{'foo':'bar'}),

和官方文档一样.
views.py

def year_archive(request,year,foo): return (year,foo)#或者输出其中个一个

那么这个形式能体现什么呢?具体使用的话在什么地方可以使用呢?
谢谢

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all (1)
左手右手慢动作

This usage is mainly useful when passing additional parameters to the view. In fact, it can be regarded as a default parameter of the view. In general urlconf, such as:

url('^blog/(?P[0-9]{4})/$', views.year_archive),

can only matchblog/2016/this URL, and:

url('^blog/(?P[0-9]{4})/$', views.year_archive,{'foo':'bar'}),

It is equivalent toblog/2016/foo.

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!