0
我需要通過https
來測試我的APP,但在使用Python運行我的應用程序時出現以下錯誤。使用Python和Django通過https運行應用程序時出錯
This site can’t provide a secure connection
127.0.0.1 sent an invalid response.
ERR_SSL_PROTOCOL_ERROR
我正在使用Python和Django的一個應用程序,並希望在https
運行。我的settings.py
如下。
settings.py:
"""
Django settings for carClinic project.
"""
import os
""" Build paths inside the project like this: os.path.join(BASE_DIR, ...) """
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
""" SECURITY WARNING: keep the secret key used in production secret! """
SECRET_KEY = 'e8rq8bj5=w6cyiw&37s2kdys&[email protected]%c6_+-jpu-21y='
""" SECURITY WARNING: don't run with debug turned on in production! """
DEBUG = False
ALLOWED_HOSTS = ['*']
""" Application definition """
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'bookingservice'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'carClinic.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'carClinic.wsgi.application'
""" Database """
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
""" Password validation """
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
""" Internationalization """
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
SECURE_SSL_REDIRECT = True
""" Static files (CSS, JavaScript, Images) """
STATIC_URL = '/static/'
你是如何運行你的應用程序? –
正如@DanielRoseman所說,這個問題可能在前臺服務器上,而不是在Django項目中。如果前臺服務器(apache,nginx,...)嘗試使用瀏覽器獲取靜態文件(圖像或CSS文件),結果如何?服務器(而不是Django)錯誤日誌顯示這個請求是什麼? – glenfant
其實我通過運行命令「python manage.py runserver」在本地主機'https://127.0.0.1:8000 /'上運行。 – satya