Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django redirecting http -> https

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?

like image 298
blueFast Avatar asked Mar 05 '18 14:03

blueFast


People also ask

How do I change http to https in Django?

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.

What is HTTP Response redirect in Django?

HttpResponseRedirect is a subclass of HttpResponse (source code) in the Django web framework that returns the HTTP 302 status code, indicating the URL resource was found but temporarily moved to a different URL. This class is most frequently used as a return object from a Django view.

What is the difference between HttpResponseRedirect and redirect?

There is a difference between the two: In the case of HttpResponseRedirect the first argument can only be a url . redirect which will ultimately return a HttpResponseRedirect can accept a model , view , or url as it's "to" argument. So it is a little more flexible in what it can "redirect" to.

What is the difference between render and redirect in Django?

The render function Combines a given template with a given context dictionary and returns an HttpResponse object with that rendered text. You request a page and the render function returns it. The redirect function sends another request to the given url.


2 Answers

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.

like image 138
Alasdair Avatar answered Oct 06 '22 08:10

Alasdair


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.

like image 43
Saransh Singh Avatar answered Oct 06 '22 07:10

Saransh Singh