Configuring MEDIA_URL and MEDIA_ROOT in Django
📖 Scenario: You are building a Django website where users can upload images. To make sure these images are saved and served correctly, you need to set up the right settings for media files.
🎯 Goal: Set up the Django settings to handle media files by defining MEDIA_URL and MEDIA_ROOT. This will allow your website to store uploaded files in a folder and serve them through a URL.
📋 What You'll Learn
Create a variable
MEDIA_URL with the value "/media/" in settings.py.Create a variable
MEDIA_ROOT that points to a folder named media inside the project directory using BASE_DIR.Use
os.path.join to build the MEDIA_ROOT path.Add the necessary import for
os if not already present.💡 Why This Matters
🌍 Real World
Websites often let users upload images or files. MEDIA_URL and MEDIA_ROOT help store and serve these files correctly.
💼 Career
Knowing how to configure media files is essential for Django developers working on real-world projects involving user content.
Progress0 / 4 steps