开发者

Using upload_to with STATICFILES_DIRS

Is it necessary to appoint MEDIA_ROOT, if indicated STATICFILES_DIRS? This issue arose when loading images - upload_to formed using MEDIA_ROOT开发者_如何学Go and ignores STATICFILES_DIRS. If actually did not necessarily how to use upload_to with STATICFILES_DIRS?


Media and Static files might seem similar on first glance, but when you dig deeper you will find that Django draws a fine line between both. While Media usually refers to files uploaded by users, static files are created and bundled together with django apps.

The idea behind static files is, that upon release you can call

./manage.py collectstatic

and have all your static files from your apps (even 3rd party ones that live in egg files) collected into a given directory your HTTP server can serve directly (without any django/wsgi in the middle) for best performance.

The same holds true for Media files, but they are uploaded by users and not created by you or other app developers.

Hope that eases your confusion :-)

I recommend you take a look at the excellent documentation at the Django homepage:

  • Static files: https://docs.djangoproject.com/en/dev/howto/static-files/
  • Managing stored files: https://docs.djangoproject.com/en/1.3/topics/files/
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜