What does Django do with `MEDIA_ROOT`?

前端 未结 3 1546
死守一世寂寞
死守一世寂寞 2021-01-05 00:06

What does Django do with MEDIA_ROOT exactly? I never understood it. Since Django itself doesn\'t serve static media, and you have to set up apache or something

相关标签:
3条回答
  • 2021-01-05 00:14

    When you creates a model with ImageField or FileField attributes, you should pass the upload_to argument. That is a relative path will be appended to your MEDIA_ROOT path and there will be save and retrieve that files.

    0 讨论(0)
  • 2021-01-05 00:26

    You're not the only one who wonders; check out Django ticket #10650. Based on the comments by Django developers there, I think this pretty much sums up what MEDIA_ROOT is used for:

    Unfortunately, Django is also at fault for being far too vague in its docs about what MEDIA_ROOT and MEDIA_URL are used for. Searching through Django's code confirms that MEDIA_ROOT & MEDIA_URL are used for file upload, and that MEDIA_URL is provided as a convenience to templates via the default context processors (available when using RequestContext??).

    0 讨论(0)
  • 2021-01-05 00:29

    It appears to be used by some classes in Django as a default -- for instance, FileSystemStorage uses it as the default place to store files.

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