success_url在UpdateView中,基于传递的值 [英] success_url in UpdateView, based on passed value
本文介绍了success_url在UpdateView中,基于传递的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何根据参数设置 success_url
?
我真的想回到我来的地方,而不是一些静态的地方。在伪代码中:
How can I set success_url
based on a parameter?
I really want to go back to where I came from, not some static place. In pseudo code:
url(r'^entry/(?P<pk>\d+)/edit/(?P<category>\d+)',
UpdateView.as_view(model=Entry,
template_name='generic_form_popup.html',
success_url='/category/%(category)')),
这将意味着:编辑条目 pk
然后返回'category'。
Which would mean: edit entry pk
and then return to 'category'. Here an entry can be part of multiple categories.
推荐答案
创建一个MyUpdateView类,从UpdateView继承并覆盖get_success_url方法:
Create a class MyUpdateView inheritted from UpdateView and override get_success_url method:
class MyUpdateView(UpdateView):
def get_success_url(self):
pass #return the appropriate success url
此外,我喜欢传递类似于继承类视图中的template_name和model的参数,但不是在.as_view )in urls.py
Also i like to pass such parameters like template_name and model inside of inheritted class view, but not in .as_view() in urls.py
这篇关于success_url在UpdateView中,基于传递的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文