我创建了一个flask应用,我也限制添加Flask-Limiter。它旨在让用户每分钟使用一次路由。如果用户再次尝试,它将重定向到自定义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")
答案 0 :(得分:1)
如v25所述-我只是将procfile更改为此:
web: gunicorn --workers 1 wsgi:app