Passing slug to CreateView

CreateView inherits from FormMixin, which calls get_success_url - which is either a function you provide to return a url or it retrieves the instance attribute named
success_url.

By default, the get_success_url method in CreateView will return self.object.get_absolute_url() - which is probably why you’re seeing a PK as an argument on the redirect.

So if you want to return to the same page, you need to override get_success_url to return the url for the page you’re on.

Thank you, I think I finally have a properly configured Comment type view for my site, I’ll have to so a little more testing to make sure, but it’s looking good so far. You’ve been an amazing help, and you always reply very promptly. Usually on reddit if someone has helped me to this degree, I send reddit gold or something, what can I do here to show my gratitude please?

1 Like

The thought is nice and is appreciated, but really not necessary. Just keep plugging away at things, and if you ever run into a situation where someone is coming to you with a question, it would be nice if you gave them a helping hand.

1 Like

Hello , Colud you share final anwer code ?

How do you get slug in CreateView?

I know how to do it on Function View

def view(request, slug):
   pass