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

Categories

class EditBlog(UpdateView):
    model = Entry
    template_name = 'entry/edit.html'
    success_url = "/"
    fields = ['entry_title', 'entry_text']

    def form_valid(self, form):
        form.instance.entry_author = self.request.user
        return super().form_valid(form)

i want to put in my success URL the name of the path because the URL of my detail page has a PK with it and it's not working the way i want


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

1 Answer

UpdateView has a method for getting the url to redirect to after the form is successfully saved, which defaults to the success_url attribute.

You could have something like:

from django.urls import reverse
class EditBlog(UpdateView):
    #Your other lines of code
    ...
    def get_success_url(self):
        return reverse("your url name", args=[self.object.pk])

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...