您好,我是使用烧瓶的新手,我一直在试图弄清楚如何限制某些网页,除非登录。我尝试了烧瓶装饰器我尝试了烧瓶装饰器但我无法理解它所以我尝试使用能够获得的烧瓶主体它正在运行,但仍然无法停止对该网页的访问。 代码说明
from flask_principal import Permission, RoleNeed
# create permission with a single Need, in this case a RoleNeed
user_permission = Permission(RoleNeed('User'))
@app.route('/home')
def home_page():
return render_template('home.html')
@app.route('/user')
@user_permission.require()
def do_user_index():
return Response('Only if you are a user')
@app.route('/employee')
def employee_page():
user = User.query.all()
return render_template('employee.html', user=user)
def do_employee_page():
with user_permission.require():
return redirect(url_for('login_page'))