Suppose you are building a Google website. (ok big dream)
假设您正在构建Google网站。 (好大梦)
Google has web search/youtube/email/news/etc ..
谷歌有网络搜索/ youtube / email / news / etc.
For this site, I'd like to structure my django directory like
对于这个网站,我想构建我的django目录,如
Google/
search
youtube
email
news
and so on.
等等。
How do I structure such a site?
Create an app for each even though I'm not expecting to publish any of the category as an app?
我如何构建这样的网站?为每个人创建一个应用程序即使我不希望将任何类别发布为应用程序?
Where would a common stuff (such as user model, utility modules, decorators..) would go, create a common_app?
常见的东西(例如用户模型,实用程序模块,装饰器......)会去哪里,创建一个common_app?
1 个解决方案
#1
1
Applications are reusable components for a django project that revolve around a central purpose. Applications don't need to map directly to your url structure of the website. While there is a standard structure for a django application to tie in with some of the management commands, such as tests.py
, models.py
, static files at /static/
you don't need to have any of it to be an application. For example, South is a popular django application used to provide database migrations. It adds a few management commands to manage.py
.
应用程序是围绕中心目的的django项目的可重用组件。应用程序无需直接映射到您网站的网址结构。虽然django应用程序有一个标准结构可以配合一些管理命令,例如tests.py,models.py,/ static /中的静态文件,但你不需要将它们作为一个应用程序。例如,South是一种流行的django应用程序,用于提供数据库迁移。它为manage.py添加了一些管理命令。
When you are adding functionality and it doesn't map directly to the purpose of the application, just create a new one. So instead of thinking of it a a common_app, think about what the purpose of the application would be and how it might be utilized by your other applications.
当您添加功能并且它不直接映射到应用程序的目的时,只需创建一个新功能。因此,不要将其视为common_app,而应考虑应用程序的用途以及其他应用程序如何使用它。
In my projects, I tend to create a base
application to handle the base template and static assets that are used in the base template. I'll create an accounts
application to handle the user model and implement things like password reset. To deal with global notifications from any part of my site, I'll create an alerts
application. The list can go on for a lot of the common functionality, but it's grouped in a way that revolves around a function and written as if it would be distributed.
在我的项目中,我倾向于创建一个基础应用程序来处理基本模板中使用的基本模板和静态资产。我将创建一个帐户应用程序来处理用户模型并实现密码重置等功能。要处理来自我网站任何部分的全局通知,我将创建一个警报应用程序。该列表可以继续执行许多常见功能,但它以一种围绕函数的方式进行分组,并将其编写为就像分发一样。
So, in your specific case, you'll likely have at least an application for each of the domains such as search
, youtube
, email
, and news
, but also an application for each common component you might want to use across your core domains.
因此,在您的特定情况下,您可能至少拥有针对每个域的应用程序,例如搜索,youtube,电子邮件和新闻,还有一个应用程序,用于您可能希望在核心域中使用的每个公共组件。
#1
1
Applications are reusable components for a django project that revolve around a central purpose. Applications don't need to map directly to your url structure of the website. While there is a standard structure for a django application to tie in with some of the management commands, such as tests.py
, models.py
, static files at /static/
you don't need to have any of it to be an application. For example, South is a popular django application used to provide database migrations. It adds a few management commands to manage.py
.
应用程序是围绕中心目的的django项目的可重用组件。应用程序无需直接映射到您网站的网址结构。虽然django应用程序有一个标准结构可以配合一些管理命令,例如tests.py,models.py,/ static /中的静态文件,但你不需要将它们作为一个应用程序。例如,South是一种流行的django应用程序,用于提供数据库迁移。它为manage.py添加了一些管理命令。
When you are adding functionality and it doesn't map directly to the purpose of the application, just create a new one. So instead of thinking of it a a common_app, think about what the purpose of the application would be and how it might be utilized by your other applications.
当您添加功能并且它不直接映射到应用程序的目的时,只需创建一个新功能。因此,不要将其视为common_app,而应考虑应用程序的用途以及其他应用程序如何使用它。
In my projects, I tend to create a base
application to handle the base template and static assets that are used in the base template. I'll create an accounts
application to handle the user model and implement things like password reset. To deal with global notifications from any part of my site, I'll create an alerts
application. The list can go on for a lot of the common functionality, but it's grouped in a way that revolves around a function and written as if it would be distributed.
在我的项目中,我倾向于创建一个基础应用程序来处理基本模板中使用的基本模板和静态资产。我将创建一个帐户应用程序来处理用户模型并实现密码重置等功能。要处理来自我网站任何部分的全局通知,我将创建一个警报应用程序。该列表可以继续执行许多常见功能,但它以一种围绕函数的方式进行分组,并将其编写为就像分发一样。
So, in your specific case, you'll likely have at least an application for each of the domains such as search
, youtube
, email
, and news
, but also an application for each common component you might want to use across your core domains.
因此,在您的特定情况下,您可能至少拥有针对每个域的应用程序,例如搜索,youtube,电子邮件和新闻,还有一个应用程序,用于您可能希望在核心域中使用的每个公共组件。