Philadelphia City Council, programming

Philadelphia City Council: Deployment (12/12)

So I’ve still got work to do. Not all my charts look exactly as I’d like. There’s some data I could update if I could get to the right sources. I’d like to have some maps to visualize city council districts. That will all come soon. I do want to get what I have so far publicly available.

Down the line, I’ll configure my own webserver to deploy this app. For now, I’m using pythonanywhere. Following their own documentation about setting up a django app, and looking at other resources like the Python Anywhere/Django guide at Tango with Django, I was able to work through everything I needed.

First, in the pythonanywhere bash shell, I set up a virtualenv and installed site packages just as I did locally (as described in an earlier post). I had almost all my code at github, which I then cloned into my project directory on the pythonanywhere server.

$ virtualenv -p python3.4 citycouncil

$ source ~/path/to/venv/citycouncil/bin/activate

$ pip install Django==1.7.1

$ pip install django-tables2

$ git clone

Now that I had my project uploaded to pythonanywhere, I had to create the webapp and customize the settings that I left locally or put in .gitignore.

First, I went to “add a new web app” in pythonanywhere’s web tab and selected manual configuration. From there, I chose Python 3.4. A web interface panel was set up for me. From there I set up This included setting up the path to the virtualenv, to the project itself, and the project’s file. I also needed to change the wsgi handler – I’ve included the old, commented out code along with the new lines. What you see here is the entire contents of my file.

import os
import sys

activate_this = '/home/phlcitycouncil/venvs/citycouncil/bin/'
with open(activate_this) as f:
     code = compile(, activate_this, 'exec')
     exec(code, dict(__file__=activate_this))

# add your project directory to the sys.path
project_home = u'/home/phlcitycouncil/projects/phlcitycouncil/phila_city_council'
if project_home not in sys.path:

# set environment variable to tell django where your is
os.environ['DJANGO_SETTINGS_MODULE'] = 'citycouncil.settings'

# # serve django via WSGI
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Now I needed to modify since I had it set to work locally. This included generating a new SECRET_KEY, and setting DEBUG & ALLOWED_HOSTS:

DEBUG = False



I then set the database settings and uploaded the sqlite file itself since I had kept that in .gitignore. More setup would have been required if I was using postgres or mysql.

'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'citycouncil.sqlite3'),

Finally I set up my static files on the web admin panel. This takes a url (just like what’s defined in and an actual path (to where your static files are).

That’s it. I hit “reload” on my web admin panel in pythonanywhere, and went to my site. Success!

Of course, I plan on updating this site. So I made a copy of that I stored in a different directory. When I do a git clone with my updates, I can do it to the SAME directory, overwriting the old files. I can then manually edit and to keep my pythonanywhere settings and add in anything new I’ve done.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s