Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • 3
    I'm not sure how it would redirect more than once, unless you have something else that's redirecting from https back to http somewhere, creating a loop. It should only redirect once. Commented Jan 3, 2017 at 15:04
  • 1
    Reason that @HimanshuMishra ran into issues that they are probably terminating SSL. Checking request.is_secure() is what you want because it respects the X-Forwarded-Protocol header. code.djangoproject.com/ticket/14597 Commented Aug 11, 2017 at 22:28
  • 2
    I think the change is as simple as: if not request.is_secure(): as @tuned mentions below. Commented Aug 11, 2017 at 22:29
  • 5
    Should actually be request.is_secure Commented Aug 11, 2017 at 22:39
  • I did try this but if my app is running on port 443 (https), why would the flask app be listening at port 80 (http)? Commented Jan 25, 2022 at 5:32