Django 中的管理文件夹除了命令之外还有其他用途吗?
为什么管理命令不在自己的应用程序级文件夹中?是否有其他项目可以添加到管理目录中,或者这个结构纯粹是退化的?
Why are management commands not in their own app-level folder? Are there other items which can be added to the management directory or is this structure purely vestigial?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不知道这段历史,但对我来说,它似乎是半退化的。至于其他可以放在管理目录中的东西,上面关于信号的评论暗示了一个答案。
当我试图回答这些问题时,我做的一件事就是查看贡献应用程序,看看它们是做什么的。可以找到一些有趣的内容:
auth/management/__init__.py
sites/management.py
请注意,在第二个中,管理模块是一个 .py 文件而不是一个目录。
I don't know the history, but it seems semi-vestigial to me. As for other stuff that can be put in the management dir, the comment about signals above hints at one answer.
One thing I do when trying to answer such questions is to look at the contrib apps to see what they do. Some interesting bits to be found:
auth/management/__init__.py
sites/management.py
Note that in the second one, the management module is a .py file rather than a directory.
需要放置在
management
模块中的另一件事(在management/__init__.py
或management.py
中)是django.db.models.signals.post_sync
信号。Another thing that needs to be placed in the
management
module (either inmanagement/__init__.py
ormanagement.py
) is any listeners to thedjango.db.models.signals.post_sync
signal.它是 django 总体设计的骨架。几乎每个项目都会包含多个应用程序,因此该项目实际上是具有共享配置的应用程序容器。
您可以将其他项目添加到项目级别文件夹中,但设计建议仅应添加高级跨应用程序项目。示例包括 url 和设置。
It is a skeleton of django's general design. Almost every project will contain multiple apps, so the project is really a container of apps with a shared configuration.
You can add other items to the project level folder, but the design suggests only high level cross-app items should be. Examples are urls and settings.