flask请求管道

时间:2024-10-29 18:33:50

请求管道,登录前的验证,否则重定向到登录页面。

 # coding: utf8
from flask import render_template, request, g, session, redirect, url_for, jsonify
from pycode import app
from master.menu import get_master_menu @app.before_request
def before_request():
g.menu1 = [('index', 'WMS'), ('master', '基础'), ('inbound', '入库'), ('outbound', '出库'), ('inventory', '库存')]
user = session.get('user', None)
if 'master' in request.path:
g.submenu = get_master_menu()
if user is None and request.endpoint != 'index' and request.endpoint != 'login' and request.endpoint != 'static':
return redirect(url_for('index'))