hand
_1_35_16
4
python3.X - Web - Django3.2.9
共43篇
python3.X - Web - Django3.2.9
返回栏目
0k
0.6k
0.1k
0.2k
0.1k
0.2k
6k
1k
6k
2k
2k
0.4k
0.3k
0.3k
1k
0.5k
3k
2k
0.6k
0.9k
1k
1k
3k
0.1k
0.3k
0.4k
0.4k
0.1k
0.3k
2k
1k
1k
1k
5k
1k
1k
0k
3k
2k
0k
0.1k
0.3k
0k
返回python3.X - Web - Django3.2.9栏目
作者:
贺及楼
成为作者
更新日期:2021-12-02 22:21:10
项目/config/__init__.py
# -*- coding: utf-8 -*-
# 本地开发环境
RUN_MODE = "DEVELOP"
# APP本地静态资源目录
STATIC_URL = "/static/"
# APP静态资源目录url
# REMOTE_STATIC_URL = "%sremote/" % STATIC_URL
DEBUG = True
# 本地开发数据库设置
DATABASES = {
"default": {
"ENGINE": "django.db.backends.mysql",
"NAME": "dbname", # noqa
"USER": "root",
"PASSWORD": "root",
"HOST": "127.0.0.1",
"PORT": "3306",
},
}
# -*- coding: utf-8 -*-
# 正式环境
RUN_MODE = "PRODUCT"
# APP正式环境静态资源目录
STATIC_URL = "/static/"
# APP静态资源目录url
# REMOTE_STATIC_URL = "%sremote/" % STATIC_URL
# 正式环境数据库设置
DATABASES = {
"default": {
"ENGINE": "django.db.backends.mysql",
"NAME": "dbname", # noqa
"USER": "root",
"PASSWORD": "root",
"HOST": "127.0.0.1",
"PORT": "3306",
},
}
# -*- coding: utf-8 -*-
# 预发布环境
RUN_MODE = "STAGING"
# APP预发布环境静态资源目录
STATIC_URL = "/static/"
# APP静态资源目录url
# REMOTE_STATIC_URL = "%sremote/" % STATIC_URL
DEBUG = True
# 预发布环境数据库设置
DATABASES = {
"default": {
"ENGINE": "django.db.backends.mysql",
"NAME": "dbname", # noqa
"USER": "root",
"PASSWORD": "root",
"HOST": "127.0.0.1",
"PORT": "3306",
},
}
windows下,在“系统设置”——“环境变量”——“用户变量”下,点击“新建” 添加进去
import os
# V3判断环境的环境变量为BKPAAS_ENVIRONMENT
if "BKPAAS_ENVIRONMENT" in os.environ:
ENVIRONMENT = os.getenv("BKPAAS_ENVIRONMENT", "dev")
# V2判断环境的环境变量为BK_ENV
else:
PAAS_V2_ENVIRONMENT = os.environ.get("BK_ENV", "development")
ENVIRONMENT = {
"development": "dev",
"testing": "stag",
"production": "prod",
}.get(PAAS_V2_ENVIRONMENT)
DJANGO_CONF_MODULE = "config.{env}".format(env=ENVIRONMENT)
try:
_module = __import__(DJANGO_CONF_MODULE, globals(), locals(), ["*"])
except ImportError as e:
raise ImportError("Could not import config "%s" (Is it on sys.path?): %s"
% (DJANGO_CONF_MODULE, e))
for _setting in dir(_module):
if _setting == _setting.upper():
locals()[_setting] = getattr(_module, _setting)
os.environ.get("xx")解释:
os.environ.get("xx") # os.environ是字典。get获得环境变量xx的值
os.environ.get("BK_ENV", "development") # 找BK_ENV,如果没有就输出development
__import__解释:
__import__("os",globals(),locals(),["*"]) #等价于from os import *
__import__("os",globals(),locals(),["path","pip"]) #等价于from os import path, pip
for解释:
for循环全部方法
如果全部字符都是大写
局部变量locals()的[_setting] = 获取_module的属性 _setting 值
python3.X - Web - Django3.2.9
整章节共43节
快分享给你的小伙伴吧 ~