Django和项目/应用组织 [英] Django and project/application organization

查看:110
本文介绍了Django和项目/应用组织的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始学习Django,并且对布局和组织项目和应用程序的最佳方式感到困惑。从我的理解,一个项目是您的网站作为一个整体,应用程序是构成该网站的部分?

I'm just beginning to learn Django and am a little confused on the best way to layout and organize a project and applications. From my understanding, a project is your site as a whole and applications are the pieces that make up that site?

对于第一个项目,我正在制作一个小型电子商务类型的网站将有用户,项目等...所以我应该有用户和项目应用程序?与用户注册/登录,项目标签,项目评论相关的较小部分呢?用户身份验证,标记和评论是否应该是单独的应用程序?

For a first project I am making a small e-commerce type site which will have users, items, etc... So should I have "users" and "items" applications? What about the smaller parts that would go along with those like user registration/logging in, tags for items, comments for items? Should user authentication, tagging, and commenting be separate applications as well?

基本上,我无法围绕应用程序的概念和何时分离

Basically I am having trouble on wrapping my head around the concept of what an application is and when to separate different use cases into separate applications while keeping everything manageable and DRY.

推荐答案

Ignacio正确地指出了一些应用程序提到已经存在。您还应该查看 Pinax 等项目,为其他可插拔应用程序创建自己的项目。

Ignacio is right in pointing out that some of the applications you mention already exist. You should also look at projects like Pinax for other pluggable apps that can be a starting point for your own project.

现在您的问题:Django项目是Django应用程序的集合 - 您的权限部分。 Django书更好地定义了:

Now to your question: A Django project is a collection of Django apps - that part you got right. The Django book defines it better:


项目是Django实例的集合,包括数据库配置,Django特定选项和应用程序特定设置。

"A project is a collection of settings for an instance of Django, including database configuration, Django-specific options and application-specific settings."

django书定义了一个Django应用程序< a> as:

The django book defines a Django app as:


一组Django代码,包括模型和视图,它们整合在一个Python包中,代表一个完整的Django应用程序。

"A bundle of Django code, including models and views, that lives together in a single Python package and represents a full Django application."

但是在最近的一个类中, Jacob Kaplan-Moss 我明白(记住我不是说他是这样说的),Django应用程序的所有内容都是封装常见的明确定义的行为。 即可。我也明白,拥有许多小型应用程序的 可以确定 - 比拥有一个单一的应用程序做的一切 - 而且一些应用程序只是提供模板,一些只是模型,一些完整的模板,模型和视图集合。

But in a recent class with Jacob Kaplan-Moss I understood (mind that I'm not saying that is what he said!!!) that a Django App is all about encapsulating common well defined behavior. I also understood that having many small apps is OK - better than having one monolithic app that does everything - and that some apps are just there to provide templates, some just models, some a complete collection of templates, models and views.

我的大部分项目 - 这是我们公司的内部应用程序 - 具有内部开发的通用可插拔应用程序,非常漂亮很多模板,CSS,javascript等的集合;将项目与普通的外观和感觉相结合。我在这个可插拔应用程序中没有任何意见或模型。

Most of my projects - which are internal facing apps for our company - have a common pluggable app internally developed that is pretty much a collection of templates, css, javascript, etc; that tie the projects together with a common look and feel. I have no views or models in that pluggable app.

我有一个可插拔的应用程序,也是内部开发的,它包含一堆在多个项目之间共享的模型。这些模型表示几个不同应用程序使用的常见数据库表,并在每个应用程序中复制它们,违反DRY

I have one pluggable app, also internally developed, that houses a bunch of models that are shared between multiple projects. The models represent common database tables that are used by several different apps and having them duplicated in each of the apps would violate DRY.

应用程序的一些很好的例子:

Some good example of apps:


  • 认证(Django已经有一个标准的认证应用程序)

  • gravatar支持(Pinax有)

  • 标记(可用的几个选项,Pinax有一个) / li>
  • helpdesk(我们在内部开发了一个)

以上所有内容都在解决一个逻辑问题。他们不会试图成为一个全面的解决方案... Gravatar应用程序不提供OpenID支持(还有另一个OpenID应用程序),我的帮助台内部应用程序不提供身份验证(它使用默认的django应用程序)。

All of the above are tackling one logical problem. They don't try to be a do-it-all solution... The Gravatar app doesn't provide OpenID support (there is another app for OpenID), and my helpdesk internal app does not provide authentication (it uses the default django app for that).

Django应用程序的一个坏例子将是实现身份验证,开放式支持,帮助台和项目跟踪的示例。为什么会坏?因为现在,如果要重用您的身份验证应用程序,您必须从您的全包应用程序中提取一些模型,一些视图,一些模板。如果您决定OpenId支持是您下一个项目的必备条件,您将不得不浏览应用程序的这个巨型代码,并找出哪些部分相关。

A bad example of a Django app would be one that implemented authentication, openid support, helpdesk, and project tracking. Why would that be bad? Because now if you want to reuse your authentication app you have to extricate some models, some views, some templates from your all-encompassing app. If you decide that OpenId support is a must for your next project, you will have to go through the code of this behemoth of an app and find out what parts are relevant.

一个好的Django应用程序提供了一套逻辑的操作,并且很好。

A good Django app provides one logical set of operations and does it well.

这篇关于Django和项目/应用组织的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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