Understanding Django Media Files

preview_player
Показать описание
Setting up Django media files for development is about understanding what MEDIA_URL is and MEDIA_ROOT.

MEDIA_URL is simply a URL prefix (or "slug") that tells Django what the URL should look like when accessing media files from the MEDIA_ROOT.

Since we know that, understanding the MEDIA_ROOT is simple. It's just the directory that holds the files that users upload. One directory. Holds user uploads. That's it.

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

This mysterious static () thing just generates a URL pattern in regex and appends it to the urlpatterns list.

Helpful links:

#Django #Python
Рекомендации по теме
Комментарии
Автор

Great Video!!! You really go into detail but I still understand everything you explain. And I just began learning Django.

louiseiden
Автор

best explanation on internet !! thanks buddy

sahilbisht
Автор

I'm starting to believe Django is only used for local servers... there are 1001 tutorials on how to setup media files in development but NONE for production :D

u-ux
Автор

Great explanation as i already expected based on the other video (the STATIC_ROOT One). Thanks a lot for sharing 👍👍

tomaspyth
Автор

My media files show on development, but not in production. I am not using any external object storage as it is not a big project, but I am using an external Postgres database. What could be the cause of this issue

renzoblack
Автор

Bro I want to ask a question like if i want to play an audio in backgroudn after my page loads
i will use <audio id="my_audio" src=''helo.mp3" loop="loop"></audio>
<script>
window.onload = function() {

</script>
let's suppose my audio file name is helo.mp3
so where do i store this audio file
if im storing it in static files(django) it is not playing in browser
and if im storing it media/images (django) it is not playing

yashsinha
Автор

Thank you a lot, its very helpful video to understand this theme

Lalofike
Автор

Work in production, right? Debug off?

fbsan
Автор

I want users to download a file after payment, so what should be the location to store that file.

pavan
Автор

nice explanation, you're doing well

nantimlord
Автор

thanks for this, i solve my problem with your content. very very thanks

acronproject
Автор

Thanks you very much for this tutorial its really help me.

danialshamas
Автор

is this your video? im the guy from reddit ?

atiquekhan