27š
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.
17š
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'),
)
- [Django]-@csrf_exempt does not work on generic view based class
- [Django]-Django staticfiles app help
- [Django]-How to delete files from filesystem using post_delete ā Django 1.8
3š
I solved this issue following these three steps:
- Import the os module in the settings.py:
import os
- Set the STATIC_ROOT variable to "staticfiles" in the settings.py:
STATIC_ROOT = os.path.join(BASE_DIR,'staticfiles')
- Execute the "collectstatic" command:
python manage.py collectstatic
- [Django]-RuntimeError: Model class django.contrib.sites.models.Site doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS
- [Django]-Django, after upgrade: MySQL server has gone away
- [Django]-Django 1.8 Run a specific migration
0š
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.
- [Django]-Admin page on django is broken
- [Django]-How to show a message to a django admin after saving a model?
- [Django]-Output of values() on a QuerySet with ManyToMany fields