开发者

Django: how to pass captured parameters in the url to extra parameters?

开发者 https://www.devze.com 2023-03-05 09:29 出处:网络
I remember reading somewhere that captured parameters in the url can be passed to extra parameters. For example:

I remember reading somewhere that captured parameters in the url can be passed to extra parameters. For example:

url(r'^products/(?P<object_id>\d+)/$', 
    'someview',开发者_开发技巧
    {parameter: <object_id>},
    name='someview'),

In this case, I want to pass object_id into the extra parameters. Can I do that? I simply can't remember where I read about this trick. Or maybe I don't remember well.


Here is an example:

url(
    (r'^(?P<base62_id>\w+)$', 'shortener.views.follow'),
}

... The view can access it as:

def follow(request, base62_id):


Extra parameters are just that: extra. You don't have to "pass in" the parameter in the URL because that's done by default. Extra parameters are for values that should always be passed to the view regardless of what comes from the URL itself.

0

精彩评论

暂无评论...
验证码 换一张
取 消