A Django software tool to easily manage and handle static assets like images, videos, and CSS files within a web application.
To use this feature, you simply need to add a line like this to your root URLconf:
if DEBUG:(r'^media/(?P
Once this is done, the files in the specified app's media folder will become readily available at the media/ URL as if they were located at MEDIA_ROOT. The view checks the media files in a specific order: files at MEDIA_ROOT take precedence, then apps are checked in order of INSTALLED_APPS listing. This is same as the app_directories template loader.
To ensure its ideal functioning and maintenance, it is best to place your app's static files in my_app/media/my_app/. With this, they will be served at the URL /media/my_app/. It is imperative to note that this view is intended for use during development only. Therefore, it is important to appropriately configure your web server to serve media in production.
The link_media management command is a useful tool available in the django-media-utils package. This command simplifies linking of all your media files, including those in the application directories, saving you the hassle of manually setting up symlinks or web server alias directives to mimic the functionality of the serve_app_media view.
Once your website is moved into the production phase, you can have your web server serve static files directly off the file system by running the link_media management command. This tool automatically creates symbolic links to all your media files from a specific webserver directory. For instance, the command './manage.py link_media /var/www/my_site_media' creates symbolic links to all your static files in my_site_media.
The link_media command resolves any name clashes by first checking the project MEDIA_ROOT, followed by app files in INSTALLED_APPS. The tool is non-destructive by default, meaning it does not remove or alter existing files or symbolic links in the specified directory. However, if you wish to delete all files and subdirectories in your specific directory prior to creating new symbolic links, use the --clean option. It is critical to note that link_media is only suitable for operating systems that support symbolic links.
Version 0.1.0: N/A