[英]The real difference between MEDIA_ROOT (media files) and STATIC_ROOT (static files) in python django and how to use them correctly
I just was looking for the answer and i'm still confused about it, in the end of the day i got two different answers:我只是在寻找答案,但我仍然对此感到困惑,最终我得到了两个不同的答案:
is one of them right if not be direct and simple please so everybody can understand and by how to use them correctly i mean what kind of files to put in them exactly如果不直接和简单,是其中之一,所以每个人都可以理解以及如何正确使用它们我的意思是要准确放入什么样的文件
Understanding the real difference between MEDIA_ROOT
and STATIC_ROOT
can be confusing sometimes as both of them are related to serving files.理解MEDIA_ROOT
和STATIC_ROOT
之间的真正区别有时可能会令人困惑,因为它们都与服务文件有关。
To be clear about their differences, I could point out their uses and types of files they serve.为了清楚它们的区别,我可以指出它们的用途和它们所服务的文件类型。
STATIC_ROOT, STATIC_URL and STATICFILES_DIRS
are all used to serve the static files required for the website or application. STATIC_ROOT, STATIC_URL and STATICFILES_DIRS
都用于提供网站或应用程序所需的 static 文件。 Whereas, MEDIA_URL and MEDIA_ROOT
are used to serve the media files uploaded by a user.而MEDIA_URL and MEDIA_ROOT
用于提供用户上传的媒体文件。As you can see that the main difference lies between media and static files.如您所见,主要区别在于媒体文件和 static 文件之间。 So, let's differentiate them.所以,让我们区分它们。
So, if there is a JavaScript file named main.js
which is used to give some functionalities like show popup on button click then it is a STATIC file.因此,如果有一个名为 main.js 的main.js
文件用于提供一些功能,例如单击按钮时显示弹出窗口,那么它就是一个 STATIC 文件。 Similarly, images like website logo, or some static images displayed in the website that the user can't change by any action are also STATIC files.类似的,像网站标志这样的图像,或者网站中显示的一些用户无法通过任何操作更改的 static 图像也是 STATIC 文件。
Hence, files(as mentioned above) that are used during the development and rendering of the website are known as STATIC files and are served by STATIC_ROOT, STATIC_URL or STATICFILES_DIRS(during deployment) in Django.因此,在网站开发和渲染期间使用的文件(如上所述)称为 STATIC 文件,并由 Django 中的 STATIC_ROOT、STATIC_URL 或 STATICFILES_DIRS(部署期间)提供服务。
Now for the MEDIA files: any file that the user uploads, for example;现在对于 MEDIA 文件:例如,用户上传的任何文件; a video, or image or excel file, etc. during the normal usage of the website or application are called MEDIA files in Django.在网站或应用程序正常使用期间的视频、图像或 excel 文件等在 Django 中称为 MEDIA 文件。
MEDIA_ROOT and MEDIA_URL are used to point out the location of MEDIA files stored in your application. MEDIA_ROOT 和 MEDIA_URL 用于指出存储在应用程序中的 MEDIA 文件的位置。
Hope this makes you clear.希望这能让你清楚。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.