Static files and Media files

You should have (at least) three separate and independent directories - one for staticfiles, which gets populated during your deployment process using collectstatic, one for media files which will get populated by files being uploaded, and your project directory containing your Django application. None of these directories should reside in any of the others.
(Our internal convention is that applications are placed in /home/<project name>, static files are collected into /var/www/html/<project name>, and media files are placed in /var/media/<project name> - with appropriate subdirectories in any of these as needed. nginx is configured to serve files in /var/media and /var/www, while uwsgi runs the applications in /home.)

That depends upon whether you’re talking about a development environment or a production environment - and how you’re running your application in each.
This isn’t a “one-size-fits-all” situation where you can be given a “do-this” answer and have it guaranteed to work. You need to gain the understanding of how the URLs being generated result in a request being handled by a server - and how to configure everything to work together. If your page is generating a URL like /media/static/images/abc.jpg, then you need to ensure that whatever web server you’re running knows how to retrieve abc.jpg from whatever directory in which it resides.

(Side note: Many people believe that deployment of a Django application is one of the most difficult tasks to perform. Getting everything working together can be extremely confusing.)

1 Like