Flask限制器在部署到Heroku时不工作

2024-05-15 21:55:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经创建了一个烧瓶应用程序,我会限制添加一个烧瓶限制器也。它打算让用户每分钟使用一次路线。如果用户再次尝试,它将重定向到自定义429页面。在localhost上,它工作得绝对完美,但是在将它提交到我的Heroku应用程序时,限制器不会阻止多次使用路由。它也不会重定向到429页

app = Flask(__name__)
limiter = Limiter(
    app,
    key_func=get_remote_address,
    default_limits=["200 per day", "50 per hour"]
)

@main_bp.route('/main', methods=['POST'])
@limiter.limit("1/minute")
def text_sum():
   the code blah blah blah

@main_bp.errorhandler(429)
def ratelimit_handler(e):
    return render_template('main429.html', result = "Please try again in 1 minute")

Tags: 用户app应用程序烧瓶maindef路线重定向