[Django]-Error "You're accessing the development server over HTTPS, but it only supports HTTP"

41πŸ‘

βœ…

I think you should create different settings.py ( base_settings.py, local_settings.py, production_settings.py). And in your settings.py do something like this:

import socket
if socket.gethostname()=="Raouf-PC":
    from local_settings import *

Change β€˜Raouf-PC’ to the hostname of your PC.

P:S: I’m using Windows 10.

After doing that place the below data in your production_settings.py and save. Then clear your browser cache and visit your site in development server.

SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
SECURE_SSL_REDIRECT = True

If the above doesn’t suit your needs, then in your local_settings.py paste the below data, save and clear your browser cache and visit your site.

SESSION_COOKIE_SECURE = False
CSRF_COOKIE_SECURE = False
SECURE_SSL_REDIRECT = False

Note: at the beginning of production_setttings.py and local_settings.py put:

from base_settings.py import *

Your base settings should contain β€˜settings’ that will be used both on local and production server so you won’t be repeating it everytime.

P:S If my answer is accepted, I dedicate it to the good people on SO who have helped me in one way or the other. This is my first time of answering a question. I hope to do more in the future. πŸ™‚

πŸ‘€smack

22πŸ‘

You probably have the setting SECURE_SSL_REDIRECT set to True

This setting should be False when running the development server

17πŸ‘

Instead of using the command

python manage.py runserver

I used

python manage.py runserver 8080

Just by changing the port number, it is working for me.

πŸ‘€Deepak G

8πŸ‘

CORS_REPLACE_HTTPS_REFERER      = False
HOST_SCHEME                     = "http://"
SECURE_PROXY_SSL_HEADER         = None
SECURE_SSL_REDIRECT             = False
SESSION_COOKIE_SECURE           = False
CSRF_COOKIE_SECURE              = False
SECURE_HSTS_SECONDS             = None
SECURE_HSTS_INCLUDE_SUBDOMAINS  = False
SECURE_FRAME_DENY               = False

1. Put this settings at the end of your settings.py
2. Clear your browser cache and then run your project.

πŸ‘€Akshay Tetwar

3πŸ‘

If you are part of a team, you can use a variable to set the development environment. I use DJANGO_DEV=development

for e.g., on the computer that will be used for development, you add this to your ~/.bashrc file:

export DJANGO_DEV=true

or you can use django-environ

After that you can check, if current environment is a DEV env and set the specific values.

import os

if os.environ.get('DJANGO_ENV') is not None:
    SECURE_SSL_REDIRECT = False
    SESSION_COOKIE_SECURE = False
    CSRF_COOKIE_SECURE = False
else:
    SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
    SECURE_SSL_REDIRECT = True
    SESSION_COOKIE_SECURE = True
    CSRF_COOKIE_SECURE = True

If there are multiple settings, that you can go and define specific files as described in @yoyo’s answer.

πŸ‘€mmsilviu

1πŸ‘

Simply change the path in your .env file to http://localhost:8000/

It worked for me. I’m using the Django backend and React frontend with the Django rest framework.

1πŸ‘

Nothing above helped me so digged in setting.py and
changed this to ACCOUNT_DEFAULT_HTTP_PROTOCOL = "https"
this ACCOUNT_DEFAULT_HTTP_PROTOCOL = "http"
it fixed the problem for me hope it helps

πŸ‘€Furkan

1πŸ‘

Additionally to settings.py setup with SECURE_SSL_REDIRECT=False for development.

To fix the https redirecting for localhost:

  • Go to https://127.0.0.1:8000
  • Open developer mode in your browser
  • Disable cache on the Network tab
  • Update the page with http://127.0.0.1:8000
  • Enable cache

Or try Empty Cache and Hard Reload by right-clicking on the update icon in development mode in browser.

To open dev mode in Chrome use: Option + ⌘ + J (on macOS), or Shift + CTRL + J (on Windows/Linux)

πŸ‘€flashdrag

1πŸ‘

I know this question is old and already solved, but here it is for anyone who has a problem (as was my case today):

In my case, I followed (partially) as Huy Than proposed, after having changed SECURE_SSL_REDIRECT, CSRF_COOKIE_SECURE and SESSION_COOKIE_SECURE to False, I only cleared the cache, restarted the IDE and the browser.

I corrected the error and was able to access my website.

πŸ‘€ihaveonesun

0πŸ‘

I also recommend to be sure that you are not trying access page by some port. For example by running Django server on PyCharm with some port.

πŸ‘€RafaΕ‚

0πŸ‘

its clearly telling that you are accessing development server over https, but it only supports http.

usually we access development server like http://127.0.0.1:8000 but in your case its https://127.0.0.1:8000 as it’s mentioned we cannot access development server over https.

I have gone through the same problem, but in my case when I was sending the email verification to gmail account, I was sending endpoint as https://127.0.0.1:8000/verify. https was used instead of http, so I corrected it to http then it worked fine.

πŸ‘€Akhil S

0πŸ‘

  1. Insert the below configs at the end of your settings.py file or completely comment them out(if you already had)

    SECURE_CONTENT_TYPE_NOSNIFF = False
    SECURE_BROWSER_XSS_FILTER = False
    SECURE_SSL_REDIRECT = False
    SESSION_COOKIE_SECURE = False
    CSRF_COOKIE_SECURE = False
    X_FRAME_OPTIONS = β€˜DENY’

then-,
2. Clear your browser cache and then re-run your project.

πŸ‘€Cleo Okinda

0πŸ‘

Check the Django’s site URL. It may have https.

Disable following variables in settings.py or .env

SECURE_CONTENT_TYPE_NOSNIFF = True
SECURE_BROWSER_XSS_FILTER = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
SECURE_SSL_REDIRECT = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
CSRF_TRUSTED_ORIGINS = ['yoursite.com']

Set DEBUG as True

DEBUG = True

Clear the Django site’s(what you developed) cookies and sessions on the browser. For Google Chrome, steps are below.

Settings-> Privacy and Security -> Cookies and other site data -> See all cookies and site data -> Search your site name or IP and click β€˜Trash’ icon.

Close the browser and reload the site now.

Leave a comment