Categories
Python Answers

How to add Python Django MEDIA_URL and MEDIA_ROOT?

Spread the love

To add Python Django MEDIA_URL and MEDIA_ROOT, we add them to our URL config to serve uploaded files when developing our app locally.

For instance, we write

from django.conf import settings
from django.conf.urls.static import static

urlpatterns = patterns('',
    # ... the rest of your URLconf goes here ...
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

to call static with settings.MEDIA_URL and document_root=settings.MEDIA_ROOT to add the route to expose the uploaded files when developing our app locally.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *