Django世界中的项目和应用之间有什么区别? [英] What’s the difference between a project and an app in Django world?

查看:346
本文介绍了Django世界中的项目和应用之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Django创建我的第一个真实网站,但我仍在努力理解项目与应用之间的区别。

I am creating my first real website using Django but I am still struggling to understand the diff between a project and an app.

例如,我的网站是体育新闻网站上将包含文章,排名表和比赛和结果等部分,我的问题是,这些部分中的每个部分是否应位于整个项目中的单独应用程序中?在这种情况下,最佳做法是什么?

For example, My website is a sports news website which will contain sections like articles, ranking tables and "fixtures and results", my question is should each one of these sections be in a separate app inside a whole project or not? what is the best practice in this situation?

推荐答案

一个项目涉及整个应用程序,

A project refers to the entire application and all its parts.

一个 app 指向项目的子模块。它是自给自足的,并且不与项目中的其他应用程序交织在一起,因此,从理论上讲,您可以将其拾取并将其放到另一个项目中,而无需进行任何修改。 app 通常具有自己的 models.py (实际上可能为空)。您可能将其视为独立的python模块。一个简单的项目可能只有一个应用程序。

An app refers to a submodule of the project. It's self-sufficient and not intertwined with the other apps in the project such that, in theory, you could pick it up and plop it down into another project without any modification. An app typically has its own models.py (which might actually be empty). You might think of it as a standalone python module. A simple project might only have one app.

在您的示例中,项目是整个网站。您可以对它进行结构化,以便为文章提供一个 app ,为排名表提供一个 app ,并为设备和结果提供一个 app 。如果需要相互交互,可以通过有据可查的公共类和访问器方法来实现。

For your example, the project is the whole website. You might structure it so there is an app for articles, an app for ranking tables, and an app for fixtures and results. If they need to interact with each other, they do it through well-documented public classes and accessor methods.

要记住的主要事情是, 应用。实际上,这都是一个 project 项目,因此没有任何意义,但是请记住两个应用程序是如何相互依赖的。如果您发现一个应用程序可以解决两个问题,请将它们拆分为两个应用程序。如果您发现两个应用程序如此交织在一起,那么您将永远无法重用另一个应用程序,请将它们组合成一个应用程序。

The main thing to keep in mind is this level of interdependence between the apps. In practice it's all one project, so there's no sense in going overboard, but keep in mind how co-dependent two apps are. If you find one app is solving two problems, split them into two apps. If you find two apps are so intertwined you could never reuse one without the other, combine them into a single app.

这篇关于Django世界中的项目和应用之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆