123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- #!/usr/bin/env python
- # -*- encoding: utf-8 -*-
- '''
- @Contact : liuyuqi.gov@msn.cn
- @Time : 2023/11/09 14:21:32
- @License : Copyright © 2017-2022 liuyuqi. All Rights Reserved.
- @Desc : config file
- '''
- import os
- import random
- import string
- import logging
- from datetime import timedelta
- from dotenv import load_dotenv
- import paddlex as pdx
- if os.path.exists('.env'):
- load_dotenv('.env', verbose=True)
- class BaseConfig:
- ''' 基础配置 '''
- SUPERADMIN = 'admin'
- ASSETS_ROOT = os.getenv('ASSETS_ROOT', '/static/assets')
- STATIC_URL = '/static/'
- SECRET_KEY = os.getenv('SECRET_KEY', None)
- if not SECRET_KEY:
- SECRET_KEY = ''.join(random.choice(string.ascii_lowercase)
- for i in range(32))
- # app.secret_key = 'secret!'
- UPLOAD_FOLDER = "tmp/upload"
- # werkzeug_logger = rel_log.getLogger('werkzeug')
- # werkzeug_logger.setLevel(rel_log.ERROR)
- # # 解决缓存刷新问题
- # app.config['SEND_FILE_MAX_AGE_DEFAULT'] = timedelta(seconds=1)
- # base
- PROJECT_NAME = 'flask_blog'
- # 当前 config.py 文件目录
- DEBUG = False
- # 当前文件所在目录的绝对路径 /apps
- BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
- BASE_URL = 'http://'
- ADMIN_EMAILS = ""
- # 分页
- POST_PER_PAGE = 8 # 每页文章数
- COMMENT_PER_PAGE = 10 # 每页评论数
-
- LANGUAGE_CODE = 'zh-hans'
- TIME_ZONE = 'PRC'
- UP_DIR = os.path.join(os.path.abspath(
- os.path.dirname(__file__)), "app/static/uploads/") # 文件上传路径
- FC_DIR = os.path.join(os.path.abspath(os.path.dirname(
- __file__)), "app/static/uploads/users/") # 用户头像上传路径
- UPLOADED_PHOTOS_DEST = 'static/upload'
- UPLOADED_FILES_ALLOW = ['gif', 'jpg']
- UPLOADS_AUTOSERVE = True
- JSON_AS_ASCII = False
- # db
- SQLALCHEMY_TRACK_MODIFICATIONS = False
- DB_ENGINE = os.getenv('DB_ENGINE' , None)
- DB_USERNAME = os.getenv('DB_USERNAME' , None)
- DB_PASS = os.getenv('DB_PASS' , None)
- DB_HOST = os.getenv('DB_HOST' , None)
- DB_PORT = os.getenv('DB_PORT' , None)
- DB_NAME = os.getenv('DB_NAME' , None)
- USE_SQLITE = True
- # redis
- REDIS_HOST = os.getenv('REDIS_HOST', 'localhost')
- REDIS_PORT = os.getenv('REDIS_PORT', 6379)
- REDIS_DB = os.getenv('REDIS_DB', 0)
- REDIS_PASSWORD = os.getenv('REDIS_PASSWORD', None)
- CELERY_BROKER_URL = 'redis://{}:{}/{}'.format(REDIS_HOST, REDIS_PORT, REDIS_DB)
- # mail
- MAIL_SERVER = os.getenv('MAIL_SERVER', 'smtp.qq.com')
- MAIL_PORT = os.getenv('MAIL_PORT', 465)
- MAIL_USE_TLS = False
- MAIL_USE_SSL = True
- MAIL_DEBUG = True
- MAIL_USERNAME = os.getenv('MAIL_USERNAME', None)
- MAIL_PASSWORD = os.getenv('MAIL_PASSWORD',None) # 生成的授权码
- MAIL_DEFAULT_SENDER = MAIL_USERNAME
- # token配置
- TIMEOUT_TOKEN = 10 * 24 * 60 * 60
- TIMEOUT_EMAIL = 10 * 60
- PERMANENT_SESSION_LIFETIME= timedelta(hours=2)
- # log
- LOG_LEVEL = logging.WARN
- # 插件配置,填写插件的文件名名称,默认不启用插件。
- PLUGIN_ENABLE_FOLDERS = []
- # 七牛云
- QINIU_ACCESS_KEY = os.getenv('QINIU_ACCESS_KEY', None)
- QINIU_SECRET_KEY = os.getenv('QINIU_SECRET_KEY', None)
- QINIU_BUCKET_NAME = os.getenv('QINIU_BUCKET_NAME', None)
-
- # github
- GITHUB_CLIENT_ID = os.getenv('GITHUB_CLIENT_ID' , None)
- GITHUB_CLIENT_SECRET = os.getenv('GITHUB_CLIENT_SECRET' , None)
- if GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET:
- SOCIAL_AUTH_GITHUB = True
- @staticmethod
- def init_app(app):
- pass
-
- class DevelopmentConfig(BaseConfig):
- ''' 开发环境配置, 开启调试模式, 使用 sqlite '''
- DEBUG = True
- SQLALCHEMY_TRACK_MODIFICATIONS = True
- # SQLALCHEMY_ECHO = True
- # SQLALCHEMY_COMMIT_ON_TEARDOWN = True
- SQLALCHEMY_DATABASE_URI = 'sqlite:///../flask-note.sqlite3.db'
- class TestingConfig(BaseConfig):
- DEBUG = True
- class ProductionConfig(BaseConfig):
- DEBUG = False
- # SQLALCHEMY_DATABASE_URI = 'sqlite:///db.sqlite3'
- SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://lyq:123456@ok.yoqi.me:13306/travel?charset=utf8'
- # Security
- SESSION_COOKIE_HTTPONLY = True
- REMEMBER_COOKIE_HTTPONLY = True
- REMEMBER_COOKIE_DURATION = 3600
- config = {
- 'default': DevelopmentConfig,
- 'development': DevelopmentConfig, # 开发环境配置, 开启调试模式, 使用 sqlite
- 'production': ProductionConfig
- }
|