from flask import Flask from flask_sqlalchemy import SQLAlchemy from .config import BaseConfig # 导入配置文件 # Flask 限流器 from flask_limiter import Limiter # from flask_limiter.util import get_remote_address, get_ipaddr # 导入过滤器 from .filter_fun import datauri app = Flask(__name__) app.config.from_object(BaseConfig) # 启用配置 app.jinja_env.filters['datauri'] = datauri app.secret_key = 'xiangpica' def get_real_ip(): if request.headers.getlist("X-Forwarded-For"): return request.headers.getlist("X-Forwarded-For")[0] return request.remote_addr limiter = Limiter(app, key_func=get_real_ip) # limiter = Limiter(app, key_func=get_ipaddr) db = SQLAlchemy() db.init_app(app) # 初始化数据库 # 导入路由配置 from app import routes from app import general from .school.index import * from .file.index import * from .antispider.index import * from .csdn.index import * from .slow.index import * from .user.index import * from .apis.index import * from .hw.index import * app.register_blueprint(s) app.register_blueprint(f) app.register_blueprint(antispider) app.register_blueprint(cs) app.register_blueprint(slow) app.register_blueprint(u) app.register_blueprint(api) app.register_blueprint(hw)