Configuring static files
Let's fix the problem of our static and media images not showing:
- In
settings.py
(on the PythonAnywhere website), we have to add the following in bold:… STATIC_URL = 'static/' STATIC_ROOT = os.path.join(BASE_DIR,'static') # Default primary key field type # https://docs.djangoproject.com/en/4.0/ref/settings/ #default-auto-field DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' MEDIA_ROOT = os.path.join(BASE_DIR,'media') MEDIA_URL = '/media/' …
The STATIC_ROOT
variable defines a central location into which we collect all static files.
- Save the file and back in the bash console (inside the virtualenv), go to the
moviereviews
folder (where themanage.py
file is located):cd moviewreviews/
Execute the following command (Figure 12.20):
python manage.py collectstatic
This command collects all your static files from each of your app folders (including the static...