Cant redirect user to another page

I’m trying to redirect my user to a different page but add something to the redirect url.

This is my code:

def view_linkshortener_redirect(request, token):
    packet = get_object_or_404(Link, uid=token)
    url = packet.link
    if 'http://' or 'https://' in url:
        return redirect(url)
    else:
        return redirect("http://" + str(url))

The first part works, if “http://” is included in the url the user gets redirected, if not the second part of the statment gets triggered, and the user gets redirected to my own domain and to the current page but adds the redirect url to mine so it throws an page not found error obviously.

How can I redirect the user to my new page including “https//:” in the url?

Thanks for your help!

According to the docs at Django shortcut functions | Django documentation | Django, this should be able to work.

What is the value of url? What is the url to which you are being redirected?

the value of url would be in that case forum.django.com and I’m redirected to 127.0.0.1:8000/link/forum.djangoproject.com

Consider the priority of operations between the or expression and the in expression in Python. See 6. Expressions — Python 3.10.0 documentation, and think about how that affects your if statement.