Skip to content

Instantly share code, notes, and snippets.

@MaxCodeXTC
Forked from bradtraversy/python_heroku.MD
Created February 5, 2022 14:00
Show Gist options
  • Save MaxCodeXTC/3c7061b7fc43095928687474cb74bb2d to your computer and use it in GitHub Desktop.
Save MaxCodeXTC/3c7061b7fc43095928687474cb74bb2d to your computer and use it in GitHub Desktop.

Revisions

  1. @bradtraversy bradtraversy created this gist Aug 16, 2019.
    76 changes: 76 additions & 0 deletions python_heroku.MD
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,76 @@
    # Python Heroku Deployment

    > Steps to create a postgres database and deply a Python app to Heroku
    ### Install guinicorn locally
    ```
    pipenv install gunicorn
    or
    pip install gunicorn
    ```

    ### Install Heroku CLI
    https://devcenter.heroku.com/articles/heroku-cli

    ### Login via CLI
    ```
    heroku login
    ```

    ### Create app
    ```
    heroku create appname
    ```

    ### Create database
    ```
    heroku addons:create heroku-postgresql:hobby-dev --app appname
    ```

    ### Get URI
    ```
    heroku config --app appname
    # Add to your app
    ```

    ### Create Procfile
    ```
    touch Procfile
    # Add this
    web: gunicorn app:app
    ```

    ### Create requirements.txt
    ```
    pip freeze > requirements.txt
    ```

    ### Create runtime.txt
    ```
    touch runtime.txt
    # Add this
    python-3.7.2
    ```

    ### Deploy with Git
    ```
    git init
    git add . && git commit -m 'Deploy'
    heroku git:remote -a appname
    git push heroku master
    ```

    ### Add table to remote database
    ```
    heroku run python
    >>> from app import db
    >>> db.create_all()
    >>>exit()
    ```
    ### Visit app
    ```
    heroku open
    ```