0
0
Djangoframework~10 mins

MEDIA_URL and MEDIA_ROOT in Django - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set the URL path for serving media files in Django.

Django
MEDIA_URL = '[1]'
Drag options to blanks, or click blank then click option'
A/media/
B/static/
C/files/
D/assets/
Attempts:
3 left
💡 Hint
Common Mistakes
Using '/static/' instead of '/media/' for MEDIA_URL
Forgetting the trailing slash in the URL
2fill in blank
medium

Complete the code to set the filesystem path where Django will store uploaded media files.

Django
MEDIA_ROOT = os.path.join(BASE_DIR, '[1]')
Drag options to blanks, or click blank then click option'
Amedia
Bfiles
Cuploads
Dstatic
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'static' folder for MEDIA_ROOT instead of 'media'
Not joining the path with BASE_DIR
3fill in blank
hard

Fix the error in this Django settings snippet to correctly serve media files during development.

Django
urlpatterns += static(settings.[1], document_root=settings.MEDIA_ROOT)
Drag options to blanks, or click blank then click option'
ASTATIC_URL
BSTATIC_ROOT
CMEDIA_ROOT
DMEDIA_URL
Attempts:
3 left
💡 Hint
Common Mistakes
Using STATIC_URL instead of MEDIA_URL
Confusing MEDIA_ROOT and MEDIA_URL in the static() function
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps filenames to their full media paths.

Django
file_paths = {filename: os.path.join(settings.[1], filename) for filename in file_list if filename.endswith([2])}
Drag options to blanks, or click blank then click option'
AMEDIA_ROOT
B'.jpg'
C'.png'
DMEDIA_URL
Attempts:
3 left
💡 Hint
Common Mistakes
Using MEDIA_URL instead of MEDIA_ROOT for file paths
Using wrong file extension filter
5fill in blank
hard

Fill all three blanks to define a Django view that returns the URL of an uploaded media file.

Django
def get_media_url(filename):
    return settings.[1] + [2] + filename + [3]
Drag options to blanks, or click blank then click option'
AMEDIA_URL
B'/'
C''
D'media/'
Attempts:
3 left
💡 Hint
Common Mistakes
Adding extra slashes causing double slashes in URL
Using 'media/' string instead of MEDIA_URL setting