What is the difference between static files and media files in Django?

前端 未结 2 1124
悲&欢浪女
悲&欢浪女 2020-12-07 22:35

I\'m moving to Django 1.3 and find this separation of media and static files a bit confusing. Here is how default settings.py looks like:

# Abso         


        
相关标签:
2条回答
  • 2020-12-07 23:15

    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.

    0 讨论(0)
  • 2020-12-07 23:16

    Static files are meant for javascript/images etc, but media files are for user-uploaded content.

    0 讨论(0)
提交回复
热议问题