Skip to content

sandeepkv93/python-flask-sample-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Creating Flask App and deploying it in Heroku

Create a Flask App

  1. Create a virtual environment

    • In Windows
    virtualenv env
    cd env\Scripts
    .\activate
    • In Linux/Mac
    virtualenv env
    source env/bin/activate
  2. Install Flask Module

    pip install Flask --upgrade
  3. Create a .gitignore file and add the following lines

    __pycache__/
    *.py[cod]
    .vscode
    env/
    
  4. Sample Flask app which returns current Date

    from flask import Flask
    from datetime import datetime
    app = Flask(__name__)
    
    @app.route('/')
    def func():
        return str(datetime.now())
    
    if __name__ == '__main__':
        app.run()
  5. Run the app

    python app.py

    When you goto http://localhost:5000/ you should be able to see current date and time.

Deploying this app in Heroku

  1. Create a new file and name it as Procfile in the project's root folder and add the following text

    web: gunicorn app:app
    
  2. Add guicorn module and other installed modules to requirements.txt

    pip install gunicorn --upgrade
    pip freeze > requirements.txt
  3. Specify a python runtime. Example: python-3.6.2

    • Create a file called runtime.txt in the project's root folder and add the following text
    python-3.6.2
    
  4. Create a heroku app

    heroku create flaskdemoapp
  5. Initialize git and add remote as heroku

    git init
    git remote add prod git@heroku.com:flaskdemoapp.git
  6. Commit and push

    git add .
    git commit -m "Your message"
    git push -u prod master
  7. Incase if you had not added public key, then

    heroku login #Username & Password
    heroku keys:add ~/.ssh/id_rsa.pub

About

Starter code for Python Flask and Deployment in Heroku

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published