是否有Django应用程序的命名约定 [英] Is there a naming convention for Django apps

查看:155
本文介绍了是否有Django应用程序的命名约定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有创建由多个单词组成的Django应用程序的首选命名约定?例如,以下哪项是首选?

Is there a preferred naming convention for creating a Django app consisting of more than one word? For instance, which of the following is preferred?


  1. my_django_app

  2. my-django-app 更新:不允许在语法上

  3. mydjangoapp 推荐解决方案

  1. my_django_app
  2. my-django-app Update: Not allowed syntactically
  3. mydjangoapp Recommended solution

虽然所有这些都可能是 选项1和3在句法上允许,是否有偏好?看看Django通过将应用程序名称和型号名称与下划线组合来创建表名称的方式,我倾向于选项#1。

While all of them may be options 1 and 3 are syntactically allowed, is there a preference? Looking at the way Django creates the table names by combining the app name and the model name with an underscore, I'm leaning against option #1.

想法? p>

Thoughts?

推荐答案

它们必须是有效的包名称。这排除了2(import my-django-app将是一个语法错误)。 PEP 8 说:

They must be valid package names. That rules out 2 ("import my-django-app" would be a syntax error). PEP 8 says:


模块应该有简短的全小写名称。如果提高可读性,则可以在模块名称中使用下划线
。 Python包应该
也有简短的全小写名称,虽然使用下划线是
不鼓励。

Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability. Python packages should also have short, all-lowercase names, although the use of underscores is discouraged.

所以,1和3都是有效的,但3是推荐的方法。

So, 1 and 3 are both valid, but 3 would be the recommended approach.

这篇关于是否有Django应用程序的命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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