Skip to content

Instantly share code, notes, and snippets.

@1UC1F3R616
Last active October 24, 2020 17:31
Show Gist options
  • Save 1UC1F3R616/3bd89fb9f058c619e49e6ebfba41d83e to your computer and use it in GitHub Desktop.
Save 1UC1F3R616/3bd89fb9f058c619e49e6ebfba41d83e to your computer and use it in GitHub Desktop.

Flask-App (App with Backend written in PostgreSQL (orm-Flask-Sqlalchemy) | API | Sockets)

OS: Linux | Note: Details are not missing but it's that they are in my mind

  • Make sure You have cors code inside your Flask API's
  • Get a Heroku account and install the heroku cli.
  • Push code to a GitHub repo
  • requirements.txt and Procfile are must
pip freeze > requirements.txt
  • Procfile
  • More than 1 worker not supported | gives error that got closed for no reason and other bugs
web: gunicorn gettingstarted.wsgi
web: gunicorn -k eventlet -w 1 runner:app
heroku create AppName1
git push heroku master
heroku addons:create heroku-postgresql:hobby-dev
heroku run python # setting up database
heroku config:set STRIPE_API_KEY="ITSaSecretBABE!"
heroku pg:psql # making changes to database | UPDATE users SET admin_status=true WHERE username='admin';
heroku logs --tail
  • Running Gunicorn locally: gunicorn --bind 0.0.0.0:8000 app
  • When setting up database
from app import * # app is folder inside which I have my models, routes, api, sockets in a systematic format :: Target is-to import db
db.create_all() # Don't worry that you haven't written any PostgreSQL code, it's all done | details in mind, lol
  • Requirements.txt (Authentication: JWT :: pyJWT can also be used | Marshmallow for serialization)
Flask
Flask-SQLAlchemy
postgres
eventlet
gunicorn
Flask-SocketIO
flask-cors
flask-heroku
pyjwt==1.4.2 | pyJWT
flask-marshmallow
marshmallow-sqlalchemy

A Useful Guide

Debugging


General

Seeing all configs

heroku config

Reseting DB

heroku pg:reset DATABASE_URL
  • You can copy ur older db to new using ps:copy
heroku releases
heroku releases:info v51
heroku rollback v51
heroku git:clone -a APPNAME
git checkout deployID
git reset --hard deployID 

Some Procfile Examples

web: gunicorn -w 4 -b 0.0.0.0:$PORT -k gevent main:app
web: python wsgi.py runserver 0.0.0.0:4000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment