Posts

Showing posts from May, 2026

What is django.template.context_processors.media in Django?

What is django.template.context_processors.media in Django? If you are working with Django , you might have seen this line in your settings.py : 'django.template.context_processors.media' Let’s understand what it really means in simple words 👇 🔹 Simple Definition django.template.context_processors.media is a built-in context processor in Django that automatically makes the MEDIA_URL variable available inside all templates. 🔹 Why is it Needed? In Django, media files are user-uploaded files like: Profile images Documents Videos To display these files in HTML, we need a base URL (MEDIA_URL). Instead of passing this URL manually in every view, Django provides this context processor to make it available globally. 🔹 Example Step 1: Define in settings.py MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media') Step 2: Use in HTML Template <img src="{{ MEDIA_URL }}profile.jpg" alt="...