Answer the question
In order to leave comments, you need to log in
How to remove the endless @login_required and @admin_required?
There is a site on flask with 100500 routes.
And it is necessary to prescribe decorators for routes like a woodpecker.
For example:
@app.route('/userarea/income/')
@login_required
def user_income():
return render_template("user_index.html")
@app.route('/userarea/income/add/')
@login_required
def user_income_add():
return render_template("user_index.html")
@app.route('/adminarea/')
@login_required
@admin_required
def admin_firm():
return render_template("admin.html")
И т.д.
@app.before_request
def before_request():
g.user_id = session.get('user_id', None)
g.admin_id = session.get('admin_id', None)
if ((not g.user_id and request.path.startswith('/userarea/')) or
(not g.admin_id and request.path.startswith('/adminarea/'))):
return redirect(url_for('login'))
Answer the question
In order to leave comments, you need to log in
And what's the point of using flask if you're too lazy?
Use django, they have already added middlewares for you.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question