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

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.

主站蜘蛛池模板: 曲松县| 边坝县| 合水县| 麟游县| 广平县| 高碑店市| 京山县| 凌云县| 江口县| 黄平县| 五指山市| 平果县| 长治县| 长治县| 韩城市| 五指山市| 信宜市| 寿光市| 佳木斯市| 泌阳县| 庆安县| 基隆市| 左贡县| 凭祥市| 福州市| 大洼县| 敦煌市| 荃湾区| 昌江| 田阳县| 宝应县| 新龙县| 库伦旗| 儋州市| 青铜峡市| 武冈市| 米脂县| 广饶县| 凤冈县| 景泰县| 朝阳县|