Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

django - success_url in UpdateView, based on passed value

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)')),

Which would mean: edit entry pk and then return to 'category'. Here an entry can be part of multiple categories.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...