2013-05-16 303 views
0

我希望用户无法获取任何资产,如果他们还没有登录任何一个可以告诉我为什么下面不适合工作。的Python:瓶:所有用户的URL login_required

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) 

谢谢!

回答

1

默认情况下,如果存在static文件夹瓶有static端点,其配对static url路径到static文件夹路径。您可以将static_url_pathstatic_folder烧瓶参数更改为另一个(而不是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)