Configuring image upload
We have to configure where we wish to store our images when we add them. First, in /moviesstore/settings.py
, add the following in bold at the end of the file:
… MEDIA_ROOT = os.path.join(BASE_DIR, 'media') MEDIA_URL = '/media/'
Let’s explain the previous code:
MEDIA_ROOT
: This variable specifies the filesystem path to the directory where uploaded media files will be stored. Here,BASE_DIR
is a variable that represents the base directory of the Django project, and'media'
is the subdirectory withinBASE_DIR
where media files will be stored. So,MEDIA_ROOT
will be set to a path like/your_project_folder/media
.MEDIA_URL
: This variable specifies the URL prefix that will be used to serve media files from the web server. In this code, it’s set to'/media/'
, meaning that media files uploaded to the Django application will be accessible via URLs starting with/media/
. For example, if you...