[Fixed]-Django fails to redirect properly

1👍

The problem is that your URL is just “www.google.com”, without a protocol. When a browser is told to redirect, if there is no protocol it just treats it as a path – and since there is no initial slash either, it will treat it as a relative path and append it to the current location.

You probably need to add validation to ensure that the field contains a full URL including protocol, ie “https://www.google.com“. Alternatively your view might inspect the value and prepend “http://” or “https://” if necessary.

Leave a comment