passing url matching parameter to reverse() in urls.py
in my urls.py I need to invoke a generic CreateView that requires a success_url parameter. The "success" URL contains an identifier that I need to pass to the reverse() URL search function. I get this parameter from the URL of the CreateView. please see the code below. I need to grab the value of the <pk> parameter in the "create" url, and pass it on to the "success" url. how is this done?
thanks
konstantin
PS: using django trunk
...
url(r'^path/(?P<pk>\d+)/apply/$',
generic.CreateView.as_view(form_class=MyForm,
success_url=reverse_lazy('success', args=[???<pk>???]),
template_name='create.html'), name='create'),
url(r'path/(?P<pk>\d+)/apply/success/$',
generic.TemplateView.as_view(template_name='success.html'), n开发者_开发问答ame='success'),
...
This is explained in the documentation:
success_url
may contain dictionary string formatting, which will be interpolated against the object's field attributes. For example, you could usesuccess_url="/polls/%(slug)s/"
to redirect to a URL composed out of the slug field on a model.
精彩评论