static( settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)

I am wondering if this is a feature or a bug.

I have an ImageField defined in my model and I am administering the model in the Admin dashboard. I uploaded an image for the field via the Admin dashboard.

Admin image upload 2021-06-20_13-53-47

Unless I set up this statement in the project settings.py file:

urlpatterns = [
    path('admin/', admin.site.urls),
] + static( settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)

the image won’t show up on the browser when I click on the link for it, e.g. http://localhost:8000/image/lego_OY3g6rJ.png

Image Link 2021-06-20_13-55-32

Now the MEDIA_URL and MEDIA_ROOT is not defined anywhere in my project settings.py file. Django does not complain.

Is this the default behavior of django? I’m using the latest, 3.2.4. Thank you!

Both MEDIA_URL and MEDIA_ROOT have global defaults defined (both are set to an empty string). You can find them in django.conf.global_settings.