0
0
Djangoframework~5 mins

MEDIA_URL and MEDIA_ROOT in Django - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is MEDIA_ROOT in Django?

MEDIA_ROOT is the absolute filesystem path where Django will store user-uploaded files.

Think of it as the folder on your computer where all uploaded pictures or documents are saved.

Click to reveal answer
beginner
What does MEDIA_URL represent in Django?

MEDIA_URL is the URL that handles the media served from MEDIA_ROOT.

It is like the web address prefix you use to access uploaded files in a browser.

Click to reveal answer
intermediate
How do MEDIA_URL and MEDIA_ROOT work together?

MEDIA_ROOT stores the files on the server, and MEDIA_URL is the web path to access those files.

Imagine MEDIA_ROOT as a storage room and MEDIA_URL as the street address to visit that room.

Click to reveal answer
beginner
Where do you set MEDIA_URL and MEDIA_ROOT in a Django project?

You set both in the settings.py file of your Django project.

Example:<br>MEDIA_URL = '/media/'<br>MEDIA_ROOT = BASE_DIR / 'media'

Click to reveal answer
intermediate
Why do you need to configure MEDIA_URL and MEDIA_ROOT during development?

Because Django does not serve uploaded files automatically in development.

You must tell Django where to find files (MEDIA_ROOT) and how to serve them via URL (MEDIA_URL).

Click to reveal answer
What type of path is MEDIA_ROOT in Django?
ARelative URL path
BURL path
CAbsolute filesystem path
DDatabase path
What does MEDIA_URL usually end with?
AA slash '/'
BA file extension like '.jpg'
CA number
DA backslash '\'
Where do you configure MEDIA_ROOT and MEDIA_URL?
AIn <code>urls.py</code>
BIn <code>settings.py</code>
CIn <code>models.py</code>
DIn <code>views.py</code>
What happens if you don't set MEDIA_URL and MEDIA_ROOT?
ADjango will automatically serve files
BNo effect on file uploads
CFiles will be stored in the database
DUploaded files won't be served properly
During development, how do you serve media files?
ABy adding URL patterns to serve <code>MEDIA_URL</code> from <code>MEDIA_ROOT</code>
BBy uploading files to a CDN
CBy storing files in the database
DBy using Django's admin interface only
Explain in your own words what MEDIA_ROOT and MEDIA_URL do in a Django project.
Think about where files live and how you reach them on the web.
You got /3 concepts.
    Describe how you would configure Django to serve uploaded media files during development.
    Remember Django does not serve media files automatically in development.
    You got /4 concepts.