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.
精彩评论