I have a Django app running on Heroku/Cedar, configured as per the instructions at https://devcenter.heroku.com/articles/django
Using gunicorn as per Heroku\'s instr
I got django admin working with following edits
urls.py(at the end)
import settings
urlpatterns += patterns('',
url(r'^static/(?P<path>.*)$', 'django.views.static.serve', {
'document_root': settings.STATIC_ROOT,
}),
)
Procfile
web: gunicorn hellodjango.wsgi -b 0.0.0.0:$PORT
'django.contrib.staticfiles.views.serve'
instead of
'django.views.static.serve'
If you use runserver and configure your app with DEBUG=True, then it will serve the admin files just like on your development machine. However, this is definitely not the recommended way to do it, and I would suggest that you put them on S3.
Using the django-storages app it's very easy to configure collectstatic to automatically push all the admin files to S3. You can find directions here
Follow this to fix all static related issues with Django and heroku.
In your settings.py
paste this at the end
import os
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
STATICFILES_DIRS = (
os.path.join(BASE_DIR,'static'),
)
TEMPLATE_DIRS = (
os.path.join(BASE_DIR,'templates'),
)
STATIC_URL = '/static/'
Your template for a particular app should be in app_name/templates/app_name/
When you render template this is how you will specify template name
in views.py
.....
return render(request,'app_name/template_name.html',context)
For static files
place your files here:
project_folder/app_name/static/app_name/css
project_folder/app_name/static/app_name/js
project_folder/app_name/static/app_name/img
to access your static file use path app_name/css/style_name.css
If you follow this, all your static files will load up fine in heroku as well as in your local development machine.
It seems little late compared to the asked date. But I got into this issue and spent 30 mins on what I did wrong. So here it is the magic solution for those who might fall in this trap.
There is some problem with Heroku's django.contrib.staticfiles.urls
SOLUTION
You need to install dj-static
(Link to download) on your Heroku setup.
It's a Django middleware utility that allows to properly serve static assets from production with a WSGI server like Gunicorn.
I hope this will help someone.
Check out this post: http://matthewphiong.com/managing-django-static-files-on-heroku
If that doesn't work for you try adding the following to your urls.py after the normal url pattern tuple. Make sure you have your STATIC_ROOT set and you've run collect static on your local environment all before pushing to heroku.
urlpatterns += patterns('',
url(r'^static/(?P<path>.*)$', 'django.views.static.serve', {
'document_root': settings.STATIC_ROOT,
}),
)