import os
# django-environ
# https://django-environ.readthedocs.io/en/latest/
import environ
from django.utils.translation import ugettext_lazy as _
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Load and read .env file
# OS environment variables take precedence over variables from .env
env = environ.Env()
env.read_env(os.path.join(BASE_DIR, '.env'))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = env('SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = env.bool('DEBUG', False)```
1条答案
按热度按时间igetnqfo1#
'我建议你django-environ,检查https://django-environ.readthedocs.io/en/latest/上的文档
一旦通过pip install django-environ,create .env输入,就可以进入项目的基础:
在/.env中
之后在www.example.com中settings.py,您可以使用预定义的环境变量,如: