兼容UTF-8编码
自动转换UTF-8编码的.env文件为GBK编码 允许用户在根目录配置.env文件 (优先级:.env大于data/.env)
This commit is contained in:
+14
-1
@@ -1,7 +1,20 @@
|
||||
from starlette.config import Config
|
||||
|
||||
from utf8togbk import convert_encoding
|
||||
import os
|
||||
import shutil
|
||||
# 配置文件.env
|
||||
# 请将.env移动至data目录,方便docker部署
|
||||
|
||||
# 判断根目录下是否存在.env文件
|
||||
if os.path.exists('.env'):
|
||||
# 将文件复制到data目录
|
||||
shutil.copy('.env', 'data/.env')
|
||||
# 获取data目录下的.env文件编码,如果为utf-8编码,就转换为gbk编码
|
||||
convert_encoding('./data/.env')
|
||||
elif os.path.exists('data/.env'):
|
||||
# 获取data目录下的.env文件编码,如果为utf-8编码,就转换为gbk编码
|
||||
convert_encoding('./data/.env')
|
||||
|
||||
config = Config("data/.env")
|
||||
# 是否开启DEBUG模式
|
||||
DEBUG = config('DEBUG', cast=bool, default=False)
|
||||
|
||||
Reference in New Issue
Block a user