One way to host

A Flask web app on Heroku

(And a bunch of ways not to)

Aka. Don't be lazy, just use a database.

Planigale..

is a guessing game for matching a photo of a cute critter with their genus and species made by Lin Taylor and myself during the first half of W1.

 

Progression

  • Take cute critter data from an API source
  • Create console game using OOP
  • Adapt the console game to a web based flask application running locally
  • Pretify the layout and styling for the app
  • Host the application on heroku

Current Architecture

  • Application Code - Python w/ Flask & Jinja2
  • Container - Gunicorn
  • Storage - Redis
  • Host - Heroku

Flask is awesome

  • Annotations
  • Sessions
  • G (a helpful but sometimes confusing global)

Redis is awesome

  • Easy to set up key-value store
  • Enables server side sessions

Serialization/deserialization..

can be tricky

  • Not straightforward with nested class structure (OOP!!)
  • Used jsonpickle to make serialization easy
  • Deserialization needed careful definition of constructors. Be careful of:
    • Equality tests that rely object references
    • Updates that rely upon object references

Things that work fine locally..

but not on Heroku/Gunicorn

  • Random secret key for sessions.

  • Global variables for storing application state.

  • Pickle for serializing / deserializing objects. Just use JSON.

  • Defining global functions in jinja2 template to reference python built-ins.

Other gotchas..

that just don't work

  • Cookies are limited to 4 KB in size, so are your flask client side sessions - be mindful about what objects you're storing in session.

  • But.. Free tier of Redis to Go is limited to 5 MB. So try to limit the amount of data that you store on the server side as well.

fin.

One way to host a Flask web app on Heroku

By dvndrsn

One way to host a Flask web app on Heroku

  • 733