Skip to content

The basic template of a flask application with postgres database integration.

License

Notifications You must be signed in to change notification settings

sharonzhou/flask-postgres-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flask-Postgres Template

The basic template of a flask application with postgres database integration.

Frequently desired for a Heroku deployment.

Quickstart

  1. Clone the repo.
$ git clone git@github.com:sharonzhou/flask-postgres.git
  1. Enter the glorious directory!
$ cd flask-postgres/
  1. Install libraries.

    Ideally, into a virtual environment, e.g. with virtualenv or conda, but that is not required.

$ pip install -r requirements.txt
  1. Create a postgres database. We will link it to the flask app in the subsequent steps.

    Here's how to do it on a Mac with Homebrew, with a database named my_practical_db_name, which you can replace with a more practical database name.

$ brew services restart postgresql
$ createdb my_practical_db_name
  1. Get your database username. Below, it's my_cool_username.
$ psql my_practical_db_name

my_practical_db_name=# select current_user;

 current_user 
--------------
 my_cool_username

my_practical_db_name=# \q

  1. Link the postgres database to the Flask app.

    The link to your database includes the database type (postgres), your username (my_cool_username), the host (localhost, aka. 127.0.0.1), and your database name (my_practical_db_name).

$ export DATABASE_URL="postgresql://my_cool_username@localhost/my_practical_db_name"
  1. Start the server.
$ python run.py
  1. Open http://0.0.0.0:5000 in your browser.

  2. Check if your postgres database is integrated correctly by clicking: Add a "Thing" to your database.

  3. Modify this template to your project.

    You can begin by adding styles to the placeholder CSS file living at app/static/css/app.css, and adding scripts to the placeholder Javascript file living at app/static/js/app.js.

About

The basic template of a flask application with postgres database integration.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published