Accelerate your next web project and start with this Flask App Blueprint. This Getting Started how-to is for written for OS X / macOS.
-
Install Xcode
- Start with installing Xcode if you haven't already. You can find Xcode for free in the Apple Store
- You also need to install the Command Line Tools (CLT) of Xcode, do this by opening your Terminal and type:
xcode-select --install
- Follow the steps presented by the wizard
-
Install HomeBrew
- HomeBrew is a package manager for macOS, install it by opening your Terminal and type:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- Add the following line to your bash profile:
- Open your bash profile by typing
nano ~/.bash_profile
- Add the line:
export PATH=/usr/local/bin:$PATH
- Open your bash profile by typing
- HomeBrew is a package manager for macOS, install it by opening your Terminal and type:
-
Install Python3 with HomeBrew
- Type in your Terminal
brew install python3
- Type in your Terminal
-
Install PIP (a package manager for Python)
- In your Terminal type
sudo easy_install pip
- In your Terminal type
-
Clone the repository and create a working directory
- Run
git clone [email protected]:jelmerdejong/flask-app-blueprint.git
- Run
mv flask-app-blueprint projectname
- Run
cd projectname
- Run
-
Create a virtual environment
python3 -m venv venv
-
Activate the virtual environment
. venv/bin/activate
-
Install Packages
- Run
pip3 install -r requirements.txt
- Run
-
Setup Github Repository
- Create a new repostitory in your Github account
- Change the remote origin to point to your new repository:
git remote set-url origin https://github.com/USERNAME/NEW_REPO.git
- Push the code to your new repository:
git push origin master
-
Install Heroku Toolbelt and git it configured
-
Create Staging environment on Heroku
- Run
heroku create projectname-staging
- Run
git remote add staging https://git.heroku.com/projectname-staging.git
- Run
heroku config:set APP_SETTINGS=config.StagingConfig --remote staging
- Run
-
Create Production environment on Heroku
- Run
heroku create projectname-production
- Run
git remote add production https://git.heroku.com/projectname-production.git
- Run
heroku config:set APP_SETTINGS=config.ProductionConfig --remote production
- Run
-
Create an account on Mandrill
- Run
nano $VIRTUAL_ENV/bin/postactivate
- Add (and modify) the following line:
export MAIL_USERNAME="Your SMTP Username"
- Add (and modify) the following line:
export MAIL_PASSWORD="Your Mandrill API Key"
- Add (and modify) the following line:
export MAIL_DEFAULT_SENDER="[email protected]"
- Run
-
Setup local database
- Download and install Postgres.app
- Open Postgres.app and open psql
- Create new database:
- Run in psql:
CREATE DATABASE projectname;
- Run in psql:
-
Initialize and run database migrations 4. Run
flask db upgrade
-
Setup databases on Heroku
- Create databases:
- Run
heroku addons:add heroku-postgresql:hobby-dev --app projectname-staging
- Run
heroku addons:add heroku-postgresql:hobby-dev --app projectname-production
- Run
- Run database migrations:
- Run
heroku run python flask db upgrade --app projectname-staging
- Run
heroku run python flask db upgrade --app projectname-production
- Run
- Create databases:
-
Run locally
- Open Postgres.app
- Run
. venv/bin/activate
- Run
flask run
- Open in your browser: http://localhost:5000/
-
Make changes, and get them committed
- Run
nose2
to ensure all tests still succeed (before running nose2 make sure a database named 'test' is created) - Run
git add .
- Run
git commit -a -m "Your Commit Message"
- Run
git push origin master
to push to GitHub
- Run
-
Deploy and run on staging
- Push latest version to staging:
git push staging master
- Open in your browser: https://projectname-staging.herokuapp.com/
- Push latest version to staging:
-
Deploy and run on production
- Push latest version to production:
git push production master
- Open in your browser: https://projectname-production.herokuapp.com/
- Push latest version to production: