from flask import Blueprint, jsonify, request, redirect, url_for from flask import render_template antispider = Blueprint('antispider', __name__, url_prefix='/as') @antispider.before_request def before_request(): user_agent = request.headers.get("User-Agent") print(user_agent) if "Mozilla" in user_agent: # 允许请求通过 return None else: return "错误请求",403 @antispider.route('/show') def index(): return render_template("antispider/ua_show.html") @antispider.route('/error403') def error403(): return "缺少关键参数", 403