__init__.py 974 字节
Newer Older
梦想橡皮擦's avatar
梦想橡皮擦 已提交
1
from flask import Flask
梦想橡皮擦's avatar
梦想橡皮擦 已提交
2 3
from flask_sqlalchemy import SQLAlchemy

梦想橡皮擦's avatar
梦想橡皮擦 已提交
4
from .config import BaseConfig  # 导入配置文件
梦想橡皮擦's avatar
梦想橡皮擦 已提交
5

梦想橡皮擦's avatar
梦想橡皮擦 已提交
6 7 8 9 10 11 12
# Flask 限流器
from flask_limiter import Limiter
from flask_limiter.util import get_remote_address,get_ipaddr




梦想橡皮擦's avatar
梦想橡皮擦 已提交
13 14
app = Flask(__name__)

梦想橡皮擦's avatar
梦想橡皮擦 已提交
15
app.config.from_object(BaseConfig)  # 启用配置
梦想橡皮擦's avatar
梦想橡皮擦 已提交
16

梦想橡皮擦's avatar
梦想橡皮擦 已提交
17 18 19 20 21 22 23 24 25 26
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)


梦想橡皮擦's avatar
梦想橡皮擦 已提交
27
db = SQLAlchemy()
梦想橡皮擦's avatar
梦想橡皮擦 已提交
28
db.init_app(app)  # 初始化数据库
梦想橡皮擦's avatar
梦想橡皮擦 已提交
29 30

# 导入路由配置
梦想橡皮擦's avatar
梦想橡皮擦 已提交
31
from app import routes
梦想橡皮擦's avatar
梦想橡皮擦 已提交
32 33
from app import general
from .school.index import *
梦想橡皮擦's avatar
梦想橡皮擦 已提交
34
from .file.index import *
梦想橡皮擦's avatar
梦想橡皮擦 已提交
35
from .antispider.index import *
梦想橡皮擦's avatar
梦想橡皮擦 已提交
36
from .csdn.index import *
梦想橡皮擦's avatar
梦想橡皮擦 已提交
37
from .slow.index import *
梦想橡皮擦's avatar
梦想橡皮擦 已提交
38
app.register_blueprint(s)
梦想橡皮擦's avatar
梦想橡皮擦 已提交
39
app.register_blueprint(f)
梦想橡皮擦's avatar
梦想橡皮擦 已提交
40
app.register_blueprint(antispider)
梦想橡皮擦's avatar
梦想橡皮擦 已提交
41 42
app.register_blueprint(cs)
app.register_blueprint(slow)