所以我想在pythonanywhere上部署我的網站。我創建了virtualenv,安裝了Django以及我需要的所有應用程序。我創建了新的應用程序並將其與我從GitHub克隆的項目連接起來。下面是設置在我的web應用程序的截圖:PythonAnyWhere SECRET_KEY設置不能爲空
我的項目結構如下:
我的settings.py
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__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
ADMIN_ENABLED = 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',
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
'taggit',
'blog',
'widget_tweaks',
'ckeditor',
'ckeditor_uploader',
'user_account',
'captcha',
'mptt',
]
SITE_ID = 1
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 = 'blog_project.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'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 = 'blog_project.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
"""
# Use this for testing on local pc
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
"""
#Use this for Deployment
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'falca94$blogezzdatabase',
'USER': 'falca94',
'PASSWORD': os.environ.get('DATABASE_PASS'),
'HOST': 'falca94.mysql.pythonanywhere-services.com',
}
}
# Password validation
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
'OPTIONS': {
'min_length': 5,
},
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Django-allauth
AUTHENTICATION_BACKENDS = (
# Needed to login by username in Django admin, regardless of `allauth`
'django.contrib.auth.backends.ModelBackend',
# `allauth` specific authentication methods, such as login by e-mail
'allauth.account.auth_backends.AuthenticationBackend',
)
# Internationalization
# https://docs.djangoproject.com/en/1.10/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Europe/Belgrade'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
#'/var/www/static/',
]
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static_cdn')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'media_cdn')
#slanje maila
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_PASS')
EMAIL_PORT = 587
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
# Custom allauth settings
# Use email as the primary identifier
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_REQUIRED = True
# Make email verification mandatory to avoid junk email accounts
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
# Eliminate need to provide username, as it's a very old practice
ACCOUNT_USERNAME_REQUIRED = False
# Redirect user after logout
ACCOUNT_LOGOUT_REDIRECT_URL = "/accounts/login"
# Our personal signup form
ACCOUNT_SIGNUP_FORM_CLASS = 'user_account.forms.SignupForm'
ACCOUNT_ADAPTER = 'user_account.adapter.AccountAdapter'
# To not show the logout page after the user logs out, set ACCOUNT_LOGOUT_ON_GET = True
ACCOUNT_LOGOUT_ON_GET = False
# Configuration for DJANGO-CKEDITOR
CKEDITOR_UPLOAD_PATH = "uploads/"
CKEDITOR_RESTRICT_BY_USER = True
CKEDITOR_BROWSE_SHOW_DIRS = True
CKEDITOR_RESTRICT_BY_DATE = True
CKEDITOR_JQUERY_URL = '//ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js'
CKEDITOR_CONFIGS = {
'default': {
'skin': 'moono',
'height': 800,
},
}
和我/var/www/falca94_pythonanywhere_com_wsgi.py
# +++++++++++ DJANGO +++++++++++
# To use your own django app use code like this:
import os
import sys
#
## assuming your django settings file is at '/home/falca94/mysite/mysite/settings.py'
## and your manage.py is is at '/home/falca94/mysite/manage.py'
path = '/home/falca94/blog_project'
if path not in sys.path:
sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'blog_project.settings'
os.environ['SECRET_KEY'] = 'mysecretkey'
os.environ['EMAIL_PASS'] = 'emailpassword'
os.environ['DATABASE_PASS'] = 'databasepass'
# then, for django >=1.5:
from django.core.wsgi import get_wsgi_application
from django.contrib.staticfiles.handlers import StaticFilesHandler
application = StaticFilesHandler(get_wsgi_application())
## or, for older django <=1.4
#import django.core.handlers.wsgi
#application = django.core.handlers.wsgi.WSGIHandler()
我不明白爲什麼我收到此錯誤:
Error running WSGI application
2017-05-05 11:33:43,246 :django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
2017-05-05 11:33:43,246 : File "/var/www/falca94_pythonanywhere_com_wsgi.py", line 12, in <module>
2017-05-05 11:33:43,247 : application = StaticFilesHandler(get_wsgi_application())
2017-05-05 11:33:43,247 :
2017-05-05 11:33:43,247 : File "/home/falca94/blog_project/blog_project_env/lib/python3.6/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
2017-05-05 11:33:43,247 : django.setup(set_prefix=False)
2017-05-05 11:33:43,247 :
2017-05-05 11:33:43,247 : File "/home/falca94/blog_project/blog_project_env/lib/python3.6/site-packages/django/__init__.py", line 22, in setup
2017-05-05 11:33:43,247 : configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
2017-05-05 11:33:43,247 :
2017-05-05 11:33:43,248 : File "/home/falca94/blog_project/blog_project_env/lib/python3.6/site-packages/django/conf/__init__.py", line 56, in __getattr__
2017-05-05 11:33:43,248 : self._setup(name)
2017-05-05 11:33:43,248 :
2017-05-05 11:33:43,248 : File "/home/falca94/blog_project/blog_project_env/lib/python3.6/site-packages/django/conf/__init__.py", line 41, in _setup
2017-05-05 11:33:43,248 : self._wrapped = Settings(settings_module)
2017-05-05 11:33:43,248 :
2017-05-05 11:33:43,248 : File "/home/falca94/blog_project/blog_project_env/lib/python3.6/site-packages/django/conf/__init__.py", line 129, in __init__
2017-05-05 11:33:43,248 : raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
這看起來不正確:與'在/ var/WWW/falca94_pythonanywhere_com_wsgi.py'不匹配行的行錯誤你在那個文件中顯示。你確定你向我們展示真實文件嗎?你確定你已經重新啓動服務? – MariusSiuram