The OpenShift forums have been retired, but you can still read and search them.
For the most up-to-date information about how to use OpenShift please visit

Django static files


I've been setting up a Django 1.5 + python 2.7 website (used the community python 2.7 app). I have unfortunately been unable to get Openshift to serve static files. I've scoured the web for answers and tried several potential solutions without solution. In any case the problem seems to be a common one.

the first key element is that I collect all relevant files into (using django's collectstatic):


(for example bootstrap will be found in .../wsgi/static/js/bootstrap.js)

STATIC_URL is set to /static/. So, for example and as one would expect, the web pages will look for bootstrap in (app is called "mezz" and namespace is "epowme"):

Finally, I created a .htaccess file in the wsgi directory (also tried wsgi/static). I've tried several iterations so far, and after spending some time with Apache's documentation, the latest is:

RewriteEngine On
RewriteRule ^static/(.+)$ /static/$1 [L]

Have been banging my head against this particular wall for some time

Many thanks for your help


To better understand what's different about Python 2.7, I setup a django-example app (

Installed as it is intended (with 2.6) all works and static files are served properly. If, however, I switch to python 2.7 then I get an error when I push the repo complaining that a system variable called APPDIR is missing in application

Other people have noticed this and have suggested replacing APPDIR with OPENSHIFT_HOMEDIR (also tried OPENSHIFT_REPO_DIR as suggested elsewhere on the site but no change). Since the missing APPDIR is the only obvious difference when running the example in 2.7 then maybe this is the route to the answer.

Thanks again for any help

Check out :

Append to appname/ :

from django.conf import settings
if settings.DEBUG:    
urlpatterns += patterns('', (r'^media\/(?P<path>.*)$',
                                 {'document_root': settings.MEDIA_ROOT}),
    from django.contrib.staticfiles.urls import staticfiles_urlpatterns
    urlpatterns += staticfiles_urlpatterns()

AFAIK, python-2.7 runs under gevent/greenlet, not apache. .htaccess will not work at all.

I use Flask with gevent, from app log i see static content is still served by gevent. Static content is symlinked to wsgi/static but still requests for static content appear in application log.

We've just released a standard Python-2.7 cartridge which runs Apache just like our standard Python-2.6 cartridge. Let us know how it goes!

Works like a charm, thank you. :)

Thanks for the confirmation!