Django 应用程序有命名约定吗
创建包含多个单词的 Django 应用程序是否有首选命名约定?例如,以下哪一项是首选?
my_django_app
更新:语法上不允许my-django-app
mydjangoapp
推荐的解决方案
虽然所有这些都可能选项1和3在语法上是允许的,是否有一个偏好?看看 Django 通过将应用程序名称和模型名称与下划线组合来创建表名称的方式,我倾向于选项#1。
想法?
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
Update: Not allowed syntacticallymy-django-app
mydjangoapp
Recommended solution
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.
Thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
它们必须是有效的包名称。这就排除了 2(“import my-django-app”将是语法错误)。 PEP 8 说:
因此,1 和 3 都是有效的,但 3 是推荐的方法。
They must be valid package names. That rules out 2 ("import my-django-app" would be a syntax error). PEP 8 says:
So, 1 and 3 are both valid, but 3 would be the recommended approach.
一些很好的例子
简单地 ,
app_name
应该有简短的、全小写的名称。如果可以提高可读性,可以在模块名称中使用下划线。还应该有一个简短的名称,可以是复数和单数名称some good examples
in simple terms,
app_name
should have short, all-lowercase names. Underscores can be used in the module name if it improves readability. also should have a short name and it can be a plural and singular name应用程序目录名称必须是有效的 Python 包名称。这意味着选项 2 完全不允许作为包名称,尽管它仍然可以用于其他目的,例如文档。最终还是取决于个人风格。如果您更喜欢选项 3,请使用它。
App directory names must be a valid Python package name. This means that option 2 is completely inadmissible as a package name, although it can still be used for other purposes, such as documentation. In the end it comes down to personal style. If you prefer option 3 then use it.
我投票给1和3,但你可以检查几个流行的应用程序:
http://www.django-cms.org/
http://geodjango.org/
My votes for 1 and 3, but you can check several popular apps:
http://www.django-cms.org/
http://geodjango.org/