-
Book Overview & Buying
-
Table Of Contents
Django 4 for the Impatient
By :
We have to configure where to store our images when we add them. First, go to moviereviews/settings.py and add the following at the bottom of the file:
…
MEDIA_ROOT = os.path.join(BASE_DIR,'media')
MEDIA_URL = '/media/'
At the top of the file, add the following:
import os
Here, MEDIA_ROOT is the absolute filesystem path to the directory that will hold user-uploaded files, and we join BASE_DIR with 'media'. Also, MEDIA_URL is the URL that handles the media served from MEDIA_ROOT (refer to https://docs.djangoproject.com/en/4.0/ref/settings/ to find out more about the setting properties).
When we add a movie in admin (explained in the Adding a movie model to admin section later in this chapter), you will see the image stored inside the /moviereviews/media/ folder.