Django设计哲学

https://docs.djangoproject.com/en/3.2/misc/design-philosophies/#cache-design-philosophy

Loose coupling

低耦合

高内聚-低耦合是其设计目标。

不同的层不需要知道其它层, 除非是绝对必要。

例如:

模板系统不用知道请求

数据库层不用知道数据显示

视图系统不关心模板系统

尽管其实一个全栈系统,为了开发的便利性, 但是其内部的技术栈, 是尽可能相互独立的。

A fundamental goal of Django’s stack is loose coupling and tight cohesion. The various layers of the framework shouldn’t “know” about each other unless absolutely necessary.

For example, the template system knows nothing about Web requests, the database layer knows nothing about data display and the view system doesn’t care which template system a programmer uses.

Although Django comes with a full stack for convenience, the pieces of the stack are independent of another wherever possible.

https://www.theturninggear.com/2018/10/22/djangos-architectural-pattern/

 

Less code

低代码

其应用应该使用尽可能少的代码。

Django apps should use as little code as possible; they should lack boilerplate. Django should take full advantage of Python’s dynamic capabilities, such as introspection.

Quick development

快速开发

21世纪Web框架出发点,是是的繁琐的Web开发方面变得快速,

允许奇快的web开发速度。

The point of a Web framework in the 21st century is to make the tedious aspects of Web development fast. Django should allow for incredibly quick Web development.

Don’t repeat yourself (DRY)

不重复

每个不同的概念和数据 应该在一个,且只一个地方。

冗余性是不好的味道, 规范化是好的风格。

框架从尽可能少的代码, 推断出尽可能多的内容。

Every distinct concept and/or piece of data should live in one, and only one, place. Redundancy is bad. Normalization is good.

The framework, within reason, should deduce as much as possible from as little as possible.

Explicit is better than implicit

显示优于隐式。

这也是Python的一个核心原则。

意味着其不做让人不理解的魔幻事情。

This is a core Python principle listed in PEP 20, and it means Django shouldn’t do too much “magic.” Magic shouldn’t happen unless there’s a really good reason for it. Magic is worth using only if it creates a huge convenience unattainable in other ways, and it isn’t implemented in a way that confuses developers who are trying to learn how to use the feature.

Consistency

一致性

框架在所有的层面上应该是一致的。

从底层的编码风格, 到高层的开发者体验。

The framework should be consistent at all levels. Consistency applies to everything from low-level (the Python coding style used) to high-level (the “experience” of using Django).

出处:http://www.cnblogs.com/lightsong/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。
原文地址:https://www.cnblogs.com/lightsong/p/15360989.html