Answer a question

I have created a flask app that I would limit to add a Flask-Limiter too. It intends to let the user use the route once per minute. If the user tries again it redirects to a custom 429 page. On localhost it works absolutely perfectly, however on committing it to my Heroku app the limiter does not prevent the use from using the route multiple times. It also doesn't redirect to the 429 page.

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")

Answers

As v25 stated - I simply changed the procfile to this:

web: gunicorn --workers 1 wsgi:app
Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐