Skip to content

Instantly share code, notes, and snippets.

@K-Jay9
Last active March 20, 2021 13:32
Show Gist options
  • Select an option

  • Save K-Jay9/36e69beeaf9bc682d223e8555a7419e7 to your computer and use it in GitHub Desktop.

Select an option

Save K-Jay9/36e69beeaf9bc682d223e8555a7419e7 to your computer and use it in GitHub Desktop.
This file describes how you can create and deploy a flask application

Project setup

Initialise your git repo in the working directory with

$ git init

Initialise your pipenv environment by running

$ pipenv shell

Install the required packages for creation of the app and the deployment using Heroku

$ pipenv install flask, autoenv, gunicorn

Create a file called Procfile and add the following line

web: gunicorn app:app

Create a Heroku app using the Heroku CLI

$ heroku login $ heroku create karomoweb-stage

Add the heroku remote to your git

$ git remote add stage [email protected]:karomoweb-stage.git

You can either connect Github to your Heroku app or using Heroku's remote to update your app

Create a config.py file and add the following code

import os basedir = os.path.abspath(os.path.dirname(file))

class Config(object): DEBUG = False TESTING = False CSRF_ENABLED = True SECRET_KEY = 'this-really-needs-to-be-changed'

class ProductionConfig(Config): DEBUG = False

class StagingConfig(Config): DEVELOPMENT = True DEBUG = True

class DevelopmentConfig(Config): DEVELOPMENT = True DEBUG = True

class TestingConfig(Config): TESTING = True

Create an env file using

$ touch .env

Then add the following lines

pipenv shell export APP_SETTINGS="config.DevelopmentConfig"

We set the Heroku environment variable by running

$ heroku config:set APP_SETTINGS=config.StagingConfig --remote stage

You can also go to Heroku deploy settings and set Autodeploy everytime the master branch or the github branch is updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment