View on GitHub


A microblog application powered by Flask and Neo4j.

Download this project as a .zip file Download this project as a tar.gz file

Project Structure

The Explore Flask book provides great documentation on best practices for organizing your project. For this sample blogging application, we’re going to keep it simple:

Recall that we created requirements.txt in the previous step. Typically, the bulk of the action will take place in (where we’ll define classes, methods, etc.) and (where we’ll define our views, or site pages). The file in the blog/ directory allows it to be used as a package.

In, we’ll import the classes and functions we need from and initialize the app. is “the file that is invoked to start up a development server. It gets a copy of the app from your package and runs it. This won’t be used in production, but it will see a lot of mileage in development.” My file looks like this:

from blog import app
import os

app.secret_key = os.urandom(24)

Setting the app’s secret_key allows you to use sessions, which will be explained later. Setting debug to True allows you to see the stacktrace when anything goes wrong. When putting your application into production, however, debug should be set to False. At the end of the tutorial, we’ll start our sample blog with python and navigate to http://localhost:5000.

The blog/static directory contains CSS, JavaScript, and images, and the blog/templates directory contains our Jinja2 templates.

Note that if you’re on Neo4j 2.2 and above, you’ll need to set environment variables NEO4J_USERNAME and NEO4J_PASSWORD to your username and password, respectively:

$ export NEO4J_USERNAME=username
$ export NEO4J_PASSWORD=password

Or, set in conf/

Next: The Data Model