Recall & Review
beginner
What is the purpose of serving media files in Django during development?
Serving media files in development allows you to test and display user-uploaded content like images or documents without needing a separate web server.
Click to reveal answer
beginner
Which Django settings control where media files are stored and accessed?
MEDIA_ROOT defines the folder on your computer where media files are saved. MEDIA_URL is the URL path used to access these files in the browser.
Click to reveal answer
intermediate
How do you configure Django to serve media files during development?
You add a URL pattern using django.conf.urls.static.static() in your urls.py to serve files from MEDIA_ROOT at MEDIA_URL when DEBUG=True.
Click to reveal answer
intermediate
Why should media files not be served by Django in production?
Django’s development server is not optimized for serving files efficiently or securely. In production, a dedicated web server or cloud service should handle media files.
Click to reveal answer
beginner
What is the typical code snippet to serve media files in development in urls.py?
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
# your url patterns
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)Click to reveal answer
Which setting defines the folder where media files are stored in Django?
✗ Incorrect
MEDIA_ROOT is the folder path on your computer where media files are saved.
What function helps serve media files during development in Django's urls.py?
✗ Incorrect
The static() function is used to add URL patterns to serve media files during development.
When should Django serve media files directly?
✗ Incorrect
Django’s development server should serve media files only when DEBUG=True, i.e., during development.
What URL path is typically used to access media files in Django?
✗ Incorrect
MEDIA_URL is often set to '/media/' to access media files.
Why is it important to set DEBUG=True when serving media files in development?
✗ Incorrect
The static() helper function adds media serving URLs only if DEBUG=True to avoid serving media in production.
Explain how to set up Django to serve media files during development.
Think about settings and urls.py changes needed.
You got /4 concepts.
Why should you not use Django’s development server to serve media files in production?
Consider performance and security reasons.
You got /4 concepts.