Flask, Flask-Login & MongoDB example
Demo: http://itppylogindemo.herokuapp.com/
This code sample makes use of Flask and Flask-Login, a library that manages User registration, log in, session and logout functionality.
Download code
Create Git repo
git init
git add .
git commit -am "init commit"
Create a virtual environment
virtualenv venv
Install all requirements for app
. runpip
or
. venv/bin/activate
pip install -r requirements.txt
Create Heroku app
heroku create
Add MongoLab Starter Addon to your app, from your code directory in Terminal
heroku addons:add mongolab
Add MONGOLAB_URI from Heroku config to your .env file
heroku config --shell | grep MONGOLAB_URI >> .env
We need a SECRET_KEY for salting the user passwords.
Open your .env and add a new line
SECRET_KEY=SOMETHINGSECRETANDRANDOMHERE
DEBUG=True
We need to add this secret key to Heroku config vars too
heroku config:add SECRET_KEY=SOMETHINGSECRETANDRANDOMHERE
This will add a new key and value to the App on Heroku.
With your MONGOLAB_URI and SECRET_KEY configured in .env and on Heroku config you should be good to run the code.
Run,
. start
or
. venv/bin/activate
foreman start
Blueprints allow you to separate your app into modules removing core code from App.py and making the Blueprints little apps that get registered and work together in one large application.
foreman start
If you don't have foreman, download and install the Heroku Toolbelt
run_server.py does the following tasks to get the app ready