32

I am running:

python manage.py runserver localhost:44100 

And this is redirecting me to https:

» http http://localhost:44100/ HTTP/1.0 301 Moved Permanently Content-Type: text/html; charset=utf-8 Date: Mon, 05 Mar 2018 14:09:09 GMT Location: https://localhost:44100/ Server: WSGIServer/0.1 Python/2.7.14 X-Frame-Options: SAMEORIGIN 

Why / how is this happening? What setting does control whether Django accepts http / https?

2 Answers 2

47

The runserver command only handles http.

However if you have SECURE_SSL_REDIRECT set to True then you will be redirected from http to https.

See the Django docs on SSL/HTTPS for more information.

Sign up to request clarification or add additional context in comments.

5 Comments

How do I revert it back to the previous setting to test in dev mode?
@RemoBajwa You can set SECURE_SSL_REDIRECT=False or remove the line from your settings. Another option might be to move SECURE_SSL_REDIRECT = True into an if statement like if not DEBUG:. Once you've changed the settings, clear your browser cache so that it doesn't continue to redirect.
Thanks! Since my browser received a permanent redirection (301) I had to clear the page cache in order to get it to work.
Something else to watch out for, if you are setting from an environment variable in .env say, do NOT do SECURE_SSL_REDIRECT=os.environ['SECURE_SSL_REDIRECT'] as that is a string not a bool and does not eval to True as you might expect.
@Alasdair you are a life savior!
37

My best guess is that in the settings.py file of your project you have set

SECURE_SSL_REDIRECT = True 

which causes your http to redirect to https. You can read about it here.

If that is the case, you might want to remove that line and clear your browser cache before it starts to work as intended.

4 Comments

This one worked with me, I'm using Heroku as a host for Django application.
"clear browser cache" saved my life. Thanks @Saransh
@AshishJohnson: Happy to help since I faced a similar problem if the cache was not cleared.
@AshishJohnson in fact i think deleting search history do the thing. If anyone needs to preserve cache and cookies

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.