Django redirect is not working

10,098

It sounds like you have a relative url in the mini_instance.full_address variable. You want to make sure it has the http:// part in it too so that it will completely redirect to the new url not try and go to it relative to the django site you are on.

Here is an example from the docs of a relative and absolute url

def my_view(request):
    ...
    return redirect('/some/url/')

This also works with full URLs:

def my_view(request):
    ...
    return redirect('https://example.com/')

https://docs.djangoproject.com/en/1.10/topics/http/shortcuts/#redirect

Share:
10,098
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years
    def CompleteMini(request, mini_id):
        mini_instance = get_object_or_404(url_all, mini_address = mini_id)
        return redirect(mini_instance.full_address)
    

    I have this code but it does not redirect explicitly to the URL provided as parameter. Rather it just appends the current url with this one.