0

ログインしていない場合、ユーザーがアセットを取得できないようにしたいのですが、以下が機能しない理由を教えてください:

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)

ありがとう!

4

1 に答える 1

1

デフォルトでは、staticフォルダー フラスコが存在する場合、 url パスをフォルダー パスにマップするstaticエンドポイントがあります。引数を別の ( ではない) に変更またはフラスコすることができます。staticstaticstatic_url_pathstatic_folderstatic

静的エンドポイントにログインが必要な場合は、次のコードを試すことができます。

@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)
于 2013-05-16T21:19:24.660 に答える