Answers for "different functions for same app route"

0

different functions for same app route

from flask import Flask, request, make_response

app = Flask(__name__)

@app.route('/')
def index():
    if request.authorization.username == 'user1' and request.authorization.password == 'pass1':
        index2() # you can return index2() if that's the logged in page.
        return '<h1>You are logged in</h1>'

    return make_response('Could not verify!', 401, {'WWW-Authenticate' : 'Basic realm="Login Required"'})


def index2():
    print('In Index2')

if __name__ == '__main__':
    app.run(debug=True)
Posted by: Guest on April-21-2021

Code answers related to "different functions for same app route"

Browse Popular Code Answers by Language