Accessing MEDIA_URL & trailing slash redirect

In order to access {{ MEDIA_URL }} from templates, I added + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) to my urlpatterns.

Recently I noticed that this breaks the default APPEND_SLASH functionality in Django. I.e. I get a 404 when the trailing is missing, unless I remove + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) from urlpatterns, in which case it correctly redirects to the URL with the trailing slash.

I think I'm missing something fundamental, because it seems to me that accessing MEDIA_URL from templates is a basic requirement to display media correctly, without breaking other basic functions in Django.

Вернуться на верх