我希望用户在没有登录的情况下无法获取任何资产。任何人都可以告诉我为什么以下内容不起作用:
http://domain-name:5000/static/index.html.
即使用户未登录,也会获得index.html文件的服务。
lm.login_view = "/static/login.html"
@app.route('/',defaults={'path':''})
@app.route('/static/<path:path>')
@login_required
def root():
logging.debug('Login Required - Authenticated user. Will Redirect')
return redirect(path)
谢谢!
答案 0 :(得分:1)
默认情况下,如果存在static
文件夹,则static
端点会将static
个网址路径连接到static
文件夹路径。您可以将static_url_path
或static_folder
flask参数更改为另一个(不是static
)。
如果您想要登录静态端点,那么您可以尝试下一个代码:
@app.before_request
def check_login():
if request.endpoint == 'static' and not current_user.is_authenticated():
abort(401)
return None
或覆盖send_static_file
查看功能:
def send_static_file(self, filename):
if not current_user.is_authenticated():
abort(401)
return super(Flask, self).send_static_file(filename)