You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 True
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
@app.route('/secret-page')
@requires_auth
def secret_page():
return render_template('secret_page.html')
Alireza
The text was updated successfully, but these errors were encountered:
I'm trying to put BasicAuth in the views.py file and always getting unauthorize error with the correct Username/Pass.
http://flask.pocoo.org/snippets/8/
Alireza
The text was updated successfully, but these errors were encountered: