将url匹配参数传递给urls.py中的reverse()
在我的 urls.py 中,我需要调用一个需要 success_url 参数的通用 CreateView。 “成功”URL 包含一个标识符,我需要将其传递给reverse() URL 搜索函数。我从 CreateView 的 URL 中获取此参数。请参阅下面的代码。我需要获取
谢谢
康斯坦丁
PS:使用 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'), name='success'),
...
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'), name='success'), ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
文档对此进行了解释:
This is explained in the documentation: