84👍
Static files are meant for javascript/images etc, but media files are for user-uploaded content.
42👍
As Uku Loskit said, static files are for things like your applications’ css files, javascript files, images, etc. Media files are typically user or admin uploadable files.
Normally you will want MEDIA_ROOT
and STATIC_ROOT
to be separate directories. Keep in mind that STATIC_ROOT
is where the management command collectstatic
will place all the static files it finds. In production, you then configure your webserver to serve the files out of STATIC_ROOT
when given a request that starts with STATIC_URL
. If you are using the Django devserver for development, it will automatically serve static files.
The staticfiles application thus disentangles user uploaded media from application media, thus making deployment, backups, and version control easier. Prior to the staticfiles app, it was common for developers to have the media files mixed in with static application assets.
The 1.3 docs for staticfiles have been steadily improving; for more details, look at the how-to.
- [Django]-Django Form File Field disappears on form error
- [Django]-Mac OS X – EnvironmentError: mysql_config not found
- [Django]-Does django with mongodb make migrations a thing of the past?
-1👍
Static files:
Used for application assets such as CSS, and Javascript to design the UI of the application. Static files are expected to unchanged during the application execution. It is a common practice in Django to keep all the static files in the directory static.
All the files stored in this directory can be called using the command ‘collectstatic‘, an efficient way to call the files in Django.
Media files:
These are user-generated, applications specific such as images, documents, video, audio files, etc. Media files are generally unique to each user or application and may change frequently.
Media files are stored in the directory media in Django. Unlike static files, media files are not collected or managed by Django. Instead, Django provides utilities to handle media file uploads and serves them directly from the specified media URL.
- [Django]-Silence tqdm's output while running tests or running the code via cron
- [Django]-Django equivalent of SQL not in
- [Django]-How can I call a custom Django manage.py command directly from a test driver?