官术网_书友最值得收藏!

Best practices

In addition to design patterns, there might be a recommended approach to solving a problem. In Django, as with Python, there might be several ways to solve a problem but one idiomatic approach among those.

Python Zen and Django's design philosophy

Generally, the Python community uses the term 'Pythonic' to describe a piece of idiomatic code. It typically refers to the principles laid out in 'The Zen of Python'. Written like a poem, it is extremely useful to describe such a vague concept.

Tip

Try entering import this in a Python prompt to view 'The Zen of Python'.

Furthermore, Django developers have crisply documented their design philosophies while designing the framework at https://docs.djangoproject.com/en/dev/misc/design-philosophies/.

While the document describes the thought process behind how Django was designed, it is also useful for developers using Django to build applications. Certain principles such as Don't Repeat Yourself (DRY), loose coupling, and tight cohesion can help you write more maintainable and idiomatic Django applications.

Django or Python best practices suggested by this book would be formatted in the following manner:

Tip

Best Practice:

Use BASE_DIR in settings.py and avoid hard-coding directory names.

主站蜘蛛池模板: 宁德市| 黄浦区| 巴彦淖尔市| 辽阳县| 土默特右旗| 永兴县| 昌黎县| 大荔县| 屏山县| 年辖:市辖区| 三都| 古蔺县| 泰兴市| 鄂托克前旗| 云南省| 辽宁省| 武威市| 南陵县| 万州区| 榕江县| 西乌珠穆沁旗| 九龙坡区| 博湖县| 宁夏| 临漳县| 清水河县| 巴东县| 金堂县| 扶风县| 恭城| 苍南县| 仙游县| 上虞市| 本溪市| 深泽县| 且末县| 合阳县| 沙洋县| 周口市| 博野县| 温宿县|