Skip to content

An example app to show how to get Flask, Celery, and SQLAlchemy working together

Notifications You must be signed in to change notification settings

yjshen1982/flask-celery-sqlalchemy

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flask + Celery + SQLAlchemy Example App

This example app demonstrates how to write Celery tasks that work with Flask and SQLAlchemy. I had a hard time finding a complet example that worked correctly.

Based on the the Flask-User-Starter-App.

Code characteristics

  • Tested on Python 3.6
  • Well organized directories with lots of comments
    • app
      • commands
      • models
      • static
      • templates
      • views
    • tests
  • Includes test framework (py.test)
  • Includes database migration framework (alembic)
  • Sends error emails to admins for unhandled exceptions

Setting up a development environment

We assume that you have git and virtualenv and virtualenvwrapper installed.

# Clone the code repository into ~/dev/my_app
mkdir -p ~/dev
cd ~/dev
git clone https://github.com/lingthio/Flask-User-starter-app.git my_app

# Create the 'my_app' virtual environment
mkvirtualenv -p PATH/TO/PYTHON my_app

# Install required Python packages
cd ~/dev/my_app
workon my_app
pip install -r requirements.txt

Configuring SMTP

Copy the local_settings_example.py file to local_settings.py.

cp app/local_settings_example.py app/local_settings.py

Edit the local_settings.py file.

Specifically set all the MAIL_... settings to match your SMTP settings

Note that Google's SMTP server requires the configuration of "less secure apps". See https://support.google.com/accounts/answer/6010255?hl=en

Note that Yahoo's SMTP server requires the configuration of "Allow apps that use less secure sign in". See https://help.yahoo.com/kb/SLN27791.html

Initializing the Database

# Create DB tables and populate the roles and users tables
python manage.py init_db

# Or if you have Fabric installed:
fab init_db

Running the app

# Start the Flask development web server
python manage.py runserver

# Or if you have Fabric installed:
fab runserver

Point your web browser to http://localhost:5000/

You can make use of the following users:

  • email user@example.com with password Password1.
  • email admin@example.com with password Password1.

Running the automated tests

# Start the Flask development web server
py.test tests/

# Or if you have Fabric installed:
fab test

Trouble shooting

If you make changes in the Models and run into DB schema issues, delete the sqlite DB file app.sqlite.

Acknowledgements

With thanks to the following Flask extensions:

Flask-User-starter-app was used as a starting point for this code repository.

Authors

  • Kurt Wiersma (kwiersma at gmail.com)

About

An example app to show how to get Flask, Celery, and SQLAlchemy working together

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 80.7%
  • HTML 17.8%
  • Other 1.5%