Django: Getting Started Transcripts
Chapter: Receiving Uploads in Django
Lecture: Making the development server host media files

Login or purchase this course to watch this video and the rest of the course contents.
0:05 Unlike with static files, the Django development server will not serve media files by default.
0:11 Like static files, you shouldn't be using Django to serve these in production but you should be having your web server take care of it for you.
0:20 This is also why they tend to get served under a different URL path so you can mount it separately in Apache or nginx or whatever you're using.
0:27 The DEV server not serving these files is a pain if you're debugging so you can get around that by explicitly serving the files.
0:36 I've done that here with these two new lines. First I check if the server is in debug mode and will only serve the media files if debug is true.
0:46 If debug is true, then I use the static function from the static module to register the media directory, like a static files directory.
0:54 using the recently added media URL and media route configurations to tell static where to find those files. Remember, you should only do this in dev.
1:05 This is dangerous for several reasons, I'll get into that more in a bit.
1:09 The squiggly red lines are telling me that the imports haven't been done in this file So let me do that now, with the code and settings out of the way
1:27 let's go create those diretories and migrate the programs.


Talk Python's Mastodon Michael Kennedy's Mastodon