Reputation: 752
I'm at the stage of deploying my django project on Heroku but images on the website don't load. It seems that CSS files work properly. When I run:
python manage.py collectstatic --dry-run --noinput
and
heroku run python manage.py collectstatic --noinput
everything works and I can see that images that should be displayed on the website are collected using collectstatic
command.
What is also important, when I add an image to my database, the reloaded website is dead with server error (500)
I think there is some bug in my settings.py
or urls.py
but I cannot identify it.
Settings.py: https://github.com/dominik791/Cardom_initial_Heroku/blob/master/cardom_project/settings.py
Urls.py: https://github.com/dominik791/Cardom_initial_Heroku/blob/master/cardom_project/urls.py
Local_settings.py:
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
DEBUG = True
wsgi.py: https://github.com/dominik791/Cardom_initial_Heroku/blob/master/cardom_project/wsgi.py
Any ideas?
Upvotes: 0
Views: 607
Reputation: 599490
Static files and media files are completely different things. Static files are uploaded along with your app, are stored alongside it, and are collected with collectstatic. But media files are uploaded by users and cannot possibly be stored on Heroku's servers; after all, Heroku dynos are short-lived, and when they die the files stored on them are lost. This is fine with static files that live in git, but obviously no good for user-uploaded media files.
That is why you need to store them somewhere more central; Amazon S3 is the usual place. This question summarises the way to do this.
Upvotes: 2