pythonany其中密钥设置不能为空

2024-10-02 04:30:55 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我想在pythonanwhere上部署我的网站。我创建了virtualenv,安装了Django和我网站所需的所有应用程序。我创建了新的应用程序,并将其与我从GitHub克隆的项目连接起来。以下是我的web应用程序中设置的屏幕截图:

enter image description here

我的项目结构如下:

enter image description here

我的设置.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 = 'blogezz.master@gmail.com'
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\u com_wsgi.py在

^{pr2}$

我不明白我为什么会犯这个错误:

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

Tags: pathdjangoinpyprojectcomauthtrue
1条回答
网友
1楼 · 发布于 2024-10-02 04:30:55

您的settings.py试图从环境变量读取SECRET_KEY

SECRET_KEY = os.environ.get('SECRET_KEY')

此错误表示在您尝试运行Django应用程序的环境中未设置此环境变量。在

在Python的例子中,你可以在他们的文档中看到这个例子:https://help.pythonanywhere.com/pages/environment-variables-for-web-apps

相关问题 更多 >

    热门问题