Minor imports missing from app/views.py.
Protip: The redirect(url_for('index')) at the end of the if-block which adds the new post into the database has a very good reason of being there.
If absent, when the user refresher the browser an identical POST request with the same data will be sent to the DB. However, if present, it forces the browser to issue a GET request.
Now, if the user attempts a refresh, it will redo the GET request instead.