问题描述
是否有创建由多个单词组成的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?
-
my_django_app
- 更新:不允许在语法上
-
mydjangoapp
推荐解决方案
my_django_app
- Update: Not allowed syntactically
mydjangoapp
Recommended solution
虽然 选项1和3在句法上允许,是否有偏好?看看Django通过将应用程序名称和型号名称与下划线组合来创建表名称的方式,我倾向于选项#1。
While 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将是一个语法错误)。 说:
They must be valid package names. That rules out 2 ("import my-django-app" would be a syntax error). PEP 8 says:
所以,1和3都是有效的,但3是推荐的方法。
So, 1 and 3 are both valid, but 3 would be the recommended approach.
这篇关于是否有Django应用程序的命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!