Introduction
The Flask extensions directory helps you find extra tools that add features to your Flask web app easily.
The Flask extensions directory helps you find extra tools that add features to your Flask web app easily.
Visit https://flask.palletsprojects.com/en/latest/extensions/ to see the list of official Flask extensions.pip install Flask-Login
pip install Flask-WTF
pip install Flask-Mail
This simple Flask app uses the Flask-Login extension to prepare for user login management. It sets up the extension and runs a basic home page.
from flask import Flask from flask_login import LoginManager app = Flask(__name__) app.secret_key = 'secret-key' login_manager = LoginManager() login_manager.init_app(app) @app.route('/') def home(): return 'Welcome to Flask with Extensions!' if __name__ == '__main__': app.run(debug=True)
Always check the extension's documentation for setup details.
Extensions can save you time by adding common features quickly.
Not all extensions are official; prefer well-maintained ones.
The Flask extensions directory lists tools to add features to Flask apps.
You install extensions using pip and then integrate them in your app code.
Using extensions helps build apps faster and with less code.
Flask-Login?pip install command.pip install Flask-Login. Others are invalid commands.from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
db = SQLAlchemy(app)
@app.route('/')
def home():
return 'Hello, Flask!'
if __name__ == '__main__':
app.run()SQLAlchemy(app) do here?db = SQLAlchemy(app)from flask import Flask
from flask_mail import Mail
app = Flask(__name__)
mail = Mail()
@app.route('/')
def index():
return 'Welcome'
if __name__ == '__main__':
app.run()mail?app to Mail(app) or calling mail.init_app(app).mail = Mail() is created but not linked to app, so it won't work properly.Pass the test and this pattern moves unknown