Revised the test site to use the secret key specified in the environment variables when possible, so that the secret key and session keeps in the development environment.

This commit is contained in:
依瑪貓 2023-02-01 15:54:31 +08:00
parent 9118b631e4
commit 2964f206a6

View File

@ -17,6 +17,7 @@
"""The Mia! Accounting Flask demonstration website. """The Mia! Accounting Flask demonstration website.
""" """
import os
import typing as t import typing as t
from secrets import token_urlsafe from secrets import token_urlsafe
@ -45,7 +46,7 @@ def create_app(is_testing: bool = False) -> Flask:
app: Flask = Flask(__name__) app: Flask = Flask(__name__)
db_uri: str = "sqlite:///" if is_testing else "sqlite:///local.sqlite" db_uri: str = "sqlite:///" if is_testing else "sqlite:///local.sqlite"
app.config.from_mapping({ app.config.from_mapping({
"SECRET_KEY": token_urlsafe(32), "SECRET_KEY": os.environ.get("SECRET_KEY", token_urlsafe(32)),
"SQLALCHEMY_DATABASE_URI": db_uri, "SQLALCHEMY_DATABASE_URI": db_uri,
"BABEL_DEFAULT_LOCALE": "en", "BABEL_DEFAULT_LOCALE": "en",
"ALL_LINGUAS": "zh_Hant|正體中文,en|English,zh_Hans|简体中文", "ALL_LINGUAS": "zh_Hant|正體中文,en|English,zh_Hans|简体中文",