Django non-rel on Heroku with less and coffee-script compilation

Finally got it to work, so here’s my cheat-sheet:

Python already installed on my mac. Used easy_install, pip, and virtualenv to get python requirements met. Used Homebrew to get other resources like node.js, and then npm for node specific stuff.

Not using postgres, so I needed to install mongodb, first locally, in order to try my application out:

Then get Django-non-rel and Django MongoDB Engine installed:

As my application required user-authentication support for objects, I also added in django-permission-backend-nonrel.

Then continued by following instructions on Heroku for getting started with Django:

Added a MongoHQ datasource to my Heroku app.

Not using postgres, so used help from here to set up db connections, remove DATABASE_URL from heroku config (heroku config:remove DATABASE_URL), and fix my requirements.txt file to include the following:

My application uses less and coffee-script, so I added in django-compressor to compile my less and coffee-script files and needed node.js in order to install the required compilers.

I got some help from stackoverflow and found this to get node.js and django loaded for my heroku application:



Then since this was for a production server, I needed to get my staticfiles copied over to my STATIC_ROOT. I got a lot of help from MatthewPhiong’s blog post on Managing Django Static Files on Heroku.  I had to go into the comments and on to stackoverflow to figure out how to serve the files from Heroku (there aren’t that many of them in my application so s3 seemed like overkill – no speed issues for me).

These steps included remembering to import settings in

from django.conf import settings

if not settings.DEBUG:
urlpatterns += patterns(”,
url(r’^static/(?P.*)$’, ‘django.views.static.serve’, {‘document_root’:settings.STATIC_ROOT}),


  • Getting the correct SITE_ID requires you to push to heroku and use “heroku run python app/ shell” command to interact with your heroku application.  You’ll need to add the Site object and then grab it’s ID,, and put that into your and then push again.
  • Debug/development vs. Production caused me some issues with static files.  All I understand about this right now is that in production, django copies your static files over to a staticfiles directory from all of your project’s app static directories.  If you don’t run collectstatic, this won’t happen.  But you need to run collectstatic on the same worker as your application so they know about each other – requiring a Procfile (same link as above).   I would love to read something that  clarifies what is going on through all these steps, including using django-compressor.  Right now it works, but I don’t understand it completely.

About bamity

Front-end web developer working to improve the usability, accessibility, and performance of websites View all posts by bamity

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: