This is a simple and opiniated boilerplate for Flask apps (mostly ripped off from Miguel Grinberg's awesome Flask Mega-Tutorial).
- Code organized in Blueprints
- i18n support with Flask-Babel
- Forms with Flask-WTForms
- Database ORM with SQLAlchemy (defaults to SQLite).
- Email with Resend and email templates with MJML.
- CSS with Tailwind CSS.
- Javascript with Alpine.js and (optionally) HTMX.
- Python 3.
- Node.js/npm for developement (CSS, email template, favicons, ...).
- Make a copy of this template and
git clonethe repository you created. - Create your virtual environment and activate it:
python3 -m venv venv source venv/bin/activate - Install the dependencies:
pip install -r requirements.txt - Initiate your database migrations and create the tables:
flask db migrate # This will create a "migrations/" folder flask db upgrade # This may create an "app.db" file - Create your local environment configuration file:
cp .env.example .env - Start the app:
flask run
| Variable | Default | Description |
|---|---|---|
APP_NAME |
"App name" |
The name of the app displayed in the header, emails, user messagse, etc. |
APP_DESCRIPTION |
None |
The default <meta> description, can be overriden for any route by defining the description template variable. |
APP_SOCIAL_IMAGE |
'/social.png' |
The image used for social cards. |
MAIL_SENDER_NAME |
APP_NAME |
The name used when sending emails. |
MAIL_SENDER_EMAIL |
'noreply@example.com' |
The email used when sending emails. |
MAIL_LOGO |
'/assets/logo/logo-72x72.png' |
Logo used in the HTML email template (see app/templates/email/login.html). |
MAIL_FOOTER |
None |
A text to be included in the footer of your emails (e.g. your business address). |
SECRET_KEY |
'random-unique-secret-key' |
Secret key used for signing session cookies. |
SQLALCHEMY_DATABASE_URI |
None |
A valid database connection URI. If undefined, the app will use an SQLite database saved at app.db. |
RESEND_API_KEY |
None |
The Resend API key. If no key is provided (e.g. when developing on local), the content of the emails sent will be displayed in your terminal. |
TEMPLATES_AUTO_RELOAD |
False |
Hot reload templates when they change (for development). |
Models are defined in /app/models.py. After making any change you will need to:
- Create the migration script:
flask db migrate -m "users table" - Run the migration:
flask db upgrade #undo with "downgrade"
To create translations of your app strings:
- Generate the
.potfile:pybabel extract -F babel.cfg -k _l -o messages.pot . - Generate a language catalog for a language (in this example Spanish with
es):pybabel init -i messages.pot -d app/translations -l es - Once you've added your translations in the language catalog generated in the previous step, you can compile translations to be used by Flask:
pybabel compile -d app/translations
You'll need to add the support for additional languages in the LANGUAGES array in 'config.py.
Later on, if you need ot update translations you can run:
pybabel extract -F babel.cfg -k _l -o messages.pot .
pybabel update -i messages.pot -d app/translations
To run any of the npm commands listed below, you need to install the dev depdendencies with npm install.
- CSS: You can modify the
/app/src/main.cssfile and run the build process withnpm run css:build, ornpm run css:devif you want to watch changes. - Favicon: These files are saved in
app/static/favicon/. You can generate these files by editing thesrc/favicon.svgfile and then runningnpm run favicon. - Social cards (OG and Twitter/X): These files are saved in
app/static/social/. You can generate these files by editing thesrc/social.svgfile and then runningnpm run social. - Logo: The logo is saved in both SVG and PNG formats at multiple resolutions in
app/static/logo. You can generate these files by editing thesrc/logo.svgfile and then runningnpm run logo. - Email template: The login email templates (HTML and text) are saved in
app/templates/email/. The HTML version can be generated from the MJML template defined atsrc/login.mjmlby running thenpm run emailcommand.
You can generate all assets at once by running the npm run build command.