I have gone through every other answer and cannot seem to get anything to work for me. I am following a tutorial and trying to push my master
branch to heroku a
Summarizing ratrace's answer, the main solution is to add
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
to settings.py
. Where STATIC_ROOT is the destination to where static files are copied and from where they are served when deploying the Django app.
On this website it says to add this url pattern to your project:
urlpatterns += patterns(”, (r’^static/(?P.*)$’, ‘django.views.static.serve’, {‘document_root’: settings.STATIC_ROOT}),)
I haven't used heroku before but IF I understand correctly, it needs a path to send all the collected static files to. Usually that's in the server's settings. But the website above mentions that heroku uses an app which doesn't support static files deployment, and that's why you need a url pattern to make it get the static files from their respective places.
Also, read the entire tutorial first. They might mention your problem somewhere near the end of the tutorial in like a Notes section. Read the comments also if they exist.
I was able to make this work by getting rid of the if
statement all together and just having the following in my settings.py
.
import dj_database_url
DATABASES = {
'default': dj_database_url.config(default='postgres://localhost')
}
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
ALLOWED_HOSTS = ['*']
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)