蓝图结构:
manage.py
from s8pro import app if __name__ == '__main__': app.run()
__init__.py
from flask import Flask from .views import account from .views import admin from .views import user app = Flask(__name__) app.register_blueprint(account.ac) app.register_blueprint(admin.ad) app.register_blueprint(user.us)
account.py
from flask import Blueprint,render_template import redis ac = Blueprint('ac',__name__) @ac.route('/login') def login(): conn = redis.Redis() return render_template('login.html') @ac.route('/logout') def logout(): return '大人'
admin.py
from flask import Blueprint ad = Blueprint('ad',__name__,url_prefix='/admin') @ad.before_request def bf(): print('before_request') @ad.route('/home') def home(): return 'home' @ad.route('/xxxx') def xxxx(): return 'xxxx'
user.py
from flask import Blueprint us = Blueprint('us',__name__) @us.route('/info') def info(): return 'info'
login.html
<!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Title</title> </head> <body> <h1>用户登录</h1> </body> </html>