Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.8k views
in Technique[技术] by (71.8m points)

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

SSL connection

When I try to write the server link like http:// .... it redirects to https:// and in the terminal :

message Bad HTTP/0.9 request type ('x16x03x01x00x8bx01x00x00x87x03x01Dx118?J?x19[ò?x01<O')
You're accessing the development server over HTTPS, but it only supports HTTP.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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. :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...