config.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. '''
  4. @Contact : liuyuqi.gov@msn.cn
  5. @Time : 2023/11/09 14:21:32
  6. @License : Copyright © 2017-2022 liuyuqi. All Rights Reserved.
  7. @Desc : config file
  8. '''
  9. import os
  10. import random
  11. import string
  12. import logging
  13. from datetime import timedelta
  14. from dotenv import load_dotenv
  15. import paddlex as pdx
  16. if os.path.exists('.env'):
  17. load_dotenv('.env', verbose=True)
  18. class BaseConfig:
  19. ''' 基础配置 '''
  20. SUPERADMIN = 'admin'
  21. ASSETS_ROOT = os.getenv('ASSETS_ROOT', '/static/assets')
  22. STATIC_URL = '/static/'
  23. SECRET_KEY = os.getenv('SECRET_KEY', None)
  24. if not SECRET_KEY:
  25. SECRET_KEY = ''.join(random.choice(string.ascii_lowercase)
  26. for i in range(32))
  27. # app.secret_key = 'secret!'
  28. UPLOAD_FOLDER = "tmp/upload"
  29. # werkzeug_logger = rel_log.getLogger('werkzeug')
  30. # werkzeug_logger.setLevel(rel_log.ERROR)
  31. # # 解决缓存刷新问题
  32. # app.config['SEND_FILE_MAX_AGE_DEFAULT'] = timedelta(seconds=1)
  33. # base
  34. PROJECT_NAME = 'flask_blog'
  35. # 当前 config.py 文件目录
  36. DEBUG = False
  37. # 当前文件所在目录的绝对路径 /apps
  38. BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
  39. BASE_URL = 'http://'
  40. ADMIN_EMAILS = ""
  41. # 分页
  42. POST_PER_PAGE = 8 # 每页文章数
  43. COMMENT_PER_PAGE = 10 # 每页评论数
  44. LANGUAGE_CODE = 'zh-hans'
  45. TIME_ZONE = 'PRC'
  46. UP_DIR = os.path.join(os.path.abspath(
  47. os.path.dirname(__file__)), "app/static/uploads/") # 文件上传路径
  48. FC_DIR = os.path.join(os.path.abspath(os.path.dirname(
  49. __file__)), "app/static/uploads/users/") # 用户头像上传路径
  50. UPLOADED_PHOTOS_DEST = 'static/upload'
  51. UPLOADED_FILES_ALLOW = ['gif', 'jpg']
  52. UPLOADS_AUTOSERVE = True
  53. JSON_AS_ASCII = False
  54. # db
  55. SQLALCHEMY_TRACK_MODIFICATIONS = False
  56. DB_ENGINE = os.getenv('DB_ENGINE' , None)
  57. DB_USERNAME = os.getenv('DB_USERNAME' , None)
  58. DB_PASS = os.getenv('DB_PASS' , None)
  59. DB_HOST = os.getenv('DB_HOST' , None)
  60. DB_PORT = os.getenv('DB_PORT' , None)
  61. DB_NAME = os.getenv('DB_NAME' , None)
  62. USE_SQLITE = True
  63. # redis
  64. REDIS_HOST = os.getenv('REDIS_HOST', 'localhost')
  65. REDIS_PORT = os.getenv('REDIS_PORT', 6379)
  66. REDIS_DB = os.getenv('REDIS_DB', 0)
  67. REDIS_PASSWORD = os.getenv('REDIS_PASSWORD', None)
  68. CELERY_BROKER_URL = 'redis://{}:{}/{}'.format(REDIS_HOST, REDIS_PORT, REDIS_DB)
  69. # mail
  70. MAIL_SERVER = os.getenv('MAIL_SERVER', 'smtp.qq.com')
  71. MAIL_PORT = os.getenv('MAIL_PORT', 465)
  72. MAIL_USE_TLS = False
  73. MAIL_USE_SSL = True
  74. MAIL_DEBUG = True
  75. MAIL_USERNAME = os.getenv('MAIL_USERNAME', None)
  76. MAIL_PASSWORD = os.getenv('MAIL_PASSWORD',None) # 生成的授权码
  77. MAIL_DEFAULT_SENDER = MAIL_USERNAME
  78. # token配置
  79. TIMEOUT_TOKEN = 10 * 24 * 60 * 60
  80. TIMEOUT_EMAIL = 10 * 60
  81. PERMANENT_SESSION_LIFETIME= timedelta(hours=2)
  82. # log
  83. LOG_LEVEL = logging.WARN
  84. # 插件配置,填写插件的文件名名称,默认不启用插件。
  85. PLUGIN_ENABLE_FOLDERS = []
  86. # 七牛云
  87. QINIU_ACCESS_KEY = os.getenv('QINIU_ACCESS_KEY', None)
  88. QINIU_SECRET_KEY = os.getenv('QINIU_SECRET_KEY', None)
  89. QINIU_BUCKET_NAME = os.getenv('QINIU_BUCKET_NAME', None)
  90. # github
  91. GITHUB_CLIENT_ID = os.getenv('GITHUB_CLIENT_ID' , None)
  92. GITHUB_CLIENT_SECRET = os.getenv('GITHUB_CLIENT_SECRET' , None)
  93. if GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET:
  94. SOCIAL_AUTH_GITHUB = True
  95. @staticmethod
  96. def init_app(app):
  97. pass
  98. class DevelopmentConfig(BaseConfig):
  99. ''' 开发环境配置, 开启调试模式, 使用 sqlite '''
  100. DEBUG = True
  101. SQLALCHEMY_TRACK_MODIFICATIONS = True
  102. # SQLALCHEMY_ECHO = True
  103. # SQLALCHEMY_COMMIT_ON_TEARDOWN = True
  104. SQLALCHEMY_DATABASE_URI = 'sqlite:///../flask-note.sqlite3.db'
  105. class TestingConfig(BaseConfig):
  106. DEBUG = True
  107. class ProductionConfig(BaseConfig):
  108. DEBUG = False
  109. # SQLALCHEMY_DATABASE_URI = 'sqlite:///db.sqlite3'
  110. SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://lyq:123456@ok.yoqi.me:13306/travel?charset=utf8'
  111. # Security
  112. SESSION_COOKIE_HTTPONLY = True
  113. REMEMBER_COOKIE_HTTPONLY = True
  114. REMEMBER_COOKIE_DURATION = 3600
  115. config = {
  116. 'default': DevelopmentConfig,
  117. 'development': DevelopmentConfig, # 开发环境配置, 开启调试模式, 使用 sqlite
  118. 'production': ProductionConfig
  119. }