매우 간단한 응용 프로그램의 경우 HTTP 기본 인증으로 충분할 수 있습니다. 플라스크는 이것을 매우 쉽게 만듭니다. 특정 사용자 만 사용할 수있는 기능의 주위에 적용되는 다음과 같은 장식은 정확하게 수행 : 당신이 기본 인증을 사용하는 경우
@app.route('/secret-page')
@requires_auth
def secret_page():
return render_template('secret_page.html')
:
from functools import wraps
from flask import request, Response
def check_auth(username, password):
"""This function is called to check if a username password combination is valid. """
return username == 'admin' and password == 'secret'
def authenticate():
"""Sends a 401 response that enables basic auth"""
return Response(
'Could not verify your access level for that URL.\n'
'You have to login with proper credentials', 401,
{'WWW-Authenticate': 'Basic realm="Login Required"'})
def requires_auth(f):
@wraps(f)
def decorated(*args, **kwargs):
auth = request.authorization
if not auth or not check_auth(auth.username, auth.password):
return authenticate()
return f(*args, **kwargs)
return decorated
는 포장, 뷰 기능이 장식을 사용하려면 mod_wsgi 당신은 인증 전달을 활성화해야합니다. 그렇지 않으면 아파치가 필요한 헤더를 사용하고 응용 프로그램에 보내지 않습니다 : WSGIPassAuthorization.
명확히하기 : [Falcon] (https://falconframework.org/)을 사용하고 있습니까, 아니면 [Flask] (http://flask.pocoo.org/)를 사용하고 있습니까? 클래스/메서드에서 팔콘처럼 보이지만 설명에는 플라스크와 제목 팔콘이 나와 있습니다. – otupman
on_get은 확실히 팔콘 것입니다. 세션 관리를 원한다면 Flask가 더 좋은 선택이라고 생각합니다. 팔콘으로 비커를 사용해 보았습니다. 좋은데, 문서가 너무 명확하지 않아서 제가 오늘 홍보를하고 있습니다. – JasTonAChair