Skip to content

Instantly share code, notes, and snippets.

@maxparm
Created January 16, 2013 17:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save maxparm/4548843 to your computer and use it in GitHub Desktop.
Save maxparm/4548843 to your computer and use it in GitHub Desktop.
Django: serve static files on Heroku cedar stack 1) Make sure files are matching with following 2) Create a /static/ directory and add it to git (make sure it is added, this will trigger collect static command from heroku) 3) Make sure to have gunicorn in requirements.txt
web: python manage.py runserver 0.0.0.0:$PORT --noreload
Django==1.4.3
South==0.7.6
distribute==0.6.27
dj-database-url==0.2.1
psycopg2==2.4.6
wsgiref==0.1.2
gunicorn==0.16.1
MEDIA_URL = '/media/'
STATIC_ROOT = ''
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(os.path.abspath(os.path.dirname(__file__) + '/..'), 'static'),
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
from django.conf.urls import patterns, include, url
from django.conf import settings
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Home:
url(r'^$', 'home.views.home', name='home'),
# Admin:
url(r'^admin/', include(admin.site.urls)),
)
# Serve static files when debug false
if not settings.DEBUG:
urlpatterns += patterns('',
(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment