Home > front end >  How do you return a complete url with get_success_url(self) in django?
How do you return a complete url with get_success_url(self) in django?

Time:01-06

How do you return a url using get_success_url(self) in django without using reverse for a generic view? Basically, I want to have something as below.

def get_success_url(self):
    url = self.object.url # This is a charfield with "https://stackoverflow.com/questions/ask"
    return url 

I know that people often use reverse when returning a url, but I would like do it like above. Thank you, and please write any questions you have. By the way, I never tested the above code, but I don't know if it will work properly.

CodePudding user response:

"reverse(..)" is part of the django logic to store the url structure in urlpatterns in ONE place and then in the whole code refere to it in the moment of the request being executed via the name. If you do not want to follow that logic - feel free to store anything you like in your "object.url" and return it like you propose. You then just do not follow the django urlpattern idea. Up to you to decide if that is important or "right" in your case.

If the url targets outside our own server space, reverse is anyway not usefull as those urls are not part of your urlpattens.

  •  Tags:  
  • Related