Static files can be placed in the corresponding application in the same way that templates associated with a particular application are often placed in the application directory.
Sometimes it makes sense. Sometimes it’s not - it’s your call.
For example, I put static media in the site_media
directory (global css, global images, etc.), but I placed certain applications in app/static
. For example, if I have a Poll
application, there is a good chance that my media is needed only for polling application templates, and not for my site index.
The same goes for templates: I put my global templates (base.html) in the global template directory, but specific application templates are in myapp/templates/myapp/foo.html
.
Finally, it is especially useful for plug-in applications. For example, django static files are stored in the application, but become available in your static files directory, even if the application lives somewhere in your python path. Previously, you had to copy a media catalog or a symbolic link to it.
The staticfiles application really shines because it allows you to organize all the files associated with the application in one place: the application folder. collectstatic
takes care of everything else and makes everything available in one place for the web server.
source share