为什么 Django 静态和媒体文件夹没有预先配置?
我向我的兄弟演示了 Django 演示,他问了我以下问题:“为什么 Django 静态和媒体文件夹没有预先配置?它的目的不是成为配置框架的约定?为什么我这样做每次启动 Django 项目时都应该配置这些东西吗?”
我无法回答他。有谁可以吗?
PS:我并不是想将 Django 与其他框架进行比较。我只是想理解为什么做出这些设计决策;
I was presenting a Django demonstration to my brother and he asked me the following question(s): "Why Django static and media folders aren't pre-configured? It's purpose aren't to be a convention over configuration framework? Why I am supposed to configure these things every time I start a Django project?"
I couldn't answer to him. Does anyone can?
P.S: I don't mean to compare Django with other frameworks. I'm just trying to understand why these design decisions were made;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Django 绝对不是配置框架的约定。你的兄弟可能正在考虑 Rails,它确实遵循这个原则 - 但 Django 遵循“显式优于隐式”的 Python 原则。
Django is very definitely not a convention over configuration framework. Your brother is perhaps thinking of Rails, which does follow that principle - but Django follows the Python principle of "explicit is better than implicit".
因为 django 无论如何都不应该分发媒体文件。当您阅读文档时,您可以看到静态文件应该(并且必须)在生产中由您的服务器引擎和/或某种 CDN 分发。 Django 只是用来处理您的页面,而不是您的媒体。而当你在开发的时候,确实,你必须使用django来分发静态文件。但您可以使用 python 脚本来生成它并管理它。对我来说,最好的之一是:Django mediagenerator。这将使您的文件就像处于开发模式一样,但这将在生产中对其进行优化。
Because django shouldn't distribute media files anyway. When you read the documentation you can see that the static files should (and must) be distributed by your server engine and/or by some kind of CDN when you are in production. Django, is just here to process your pages but not your media. And when you are in development, indeed, you have to use django to distribute static files. But you can use a python script to generate it, and manage it. For me, one of the best is: Django mediagenerator. This will let your files like they are in dev mode, but this will optimize it in production.