admin 發表於 2023-4-16 08:57:23

pycharm install python-dotenv 敏感信息隔離

安裝完後 python-dotenv1)準備好 .env 檔案 (敏感信息放此處)
MODE=development
DBHOST=localhost
DBPORT=5432
DBCONN_STR=${DBHOST}:${DBPORT}2)py 檔放入如下資料
from dotenv import load_dotenv, find_dotenv,dotenv_values
config = dotenv_values(".env")
load_dotenv(find_dotenv())
hostname = os.getenv("MYSQL_HOST").lstrip()
username = os.getenv("MYSQL_USERNAME").lstrip()
password = os.getenv("MYSQL_PASSWORD").lstrip()
database = os.getenv("MYSQL_DBNAME").lstrip()               hostname = os.getenv("MYSQL_HOST")變數值前會多一空白The lstrip() method will remove leading whitespaces, newline and tab characters on a string beginning:








頁: [1]
查看完整版本: pycharm install python-dotenv 敏感信息隔離