Last active
February 16, 2023 22:27
-
-
Save rtzll/8f0f7668c4ca9813e9380b45b932e7c2 to your computer and use it in GitHub Desktop.
Using the app context in a flask blueprint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
from blueprint import sample | |
app = Flask(__name__) | |
app.register_blueprint(sample) | |
app.config['SOMETHING'] = 'something' | |
if __name__ == '__main__': | |
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Blueprint, current_app | |
sample = Blueprint('sample', __name__) | |
@sample.route('/') | |
def index(): | |
return current_app.config['SOMETHING'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run
python app.py
and visit http://localhost:5000/, there you will seesomething
.