Configuring static files
Let’s fix the problem of our static and media images not appearing:
- In PythonAnywhere, go back to the Files tab and navigate to the
settings.py
file. We need 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. - In PythonAnywhere, go to the Consoles tab, and click your Bash console. Then, connect to your virtual environment by executing the following command:
workon moviesstoreenv
Then, go to the moviesstore folder (where the manage.py file is located) by running the following command:
cd moviesstore/
Execute the following...