Django 应用程序有命名约定吗

发布于 2024-09-06 15:57:06 字数 366 浏览 4 评论 0原文

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

  1. my_django_app
  2. my-django-app 更新:语法上不允许
  3. 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?

  1. my_django_app
  2. my-django-app Update: Not allowed syntactically
  3. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

苦笑流年记忆 2024-09-13 15:57:06

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

模块应该有简短的、全小写的名称。可以使用下划线
如果可以提高可读性,则可以在模块名称中添加。 Python 包应该
也有短的、全小写的名称,尽管使用下划线是
灰心丧气。

因此,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:

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.

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

单身情人 2024-09-13 15:57:06

一些很好的例子

  • graphene_django
  • 用户
  • 订购
  • oauth2_provider
  • rest_framework
  • 民意调查

简单地 ,app_name 应该有简短的、全小写的名称。如果可以提高可读性,可以在模块名称中使用下划线。还应该有一个简短的名称,可以是复数和单数名称

some good examples

  • graphene_django
  • users
  • orders
  • oauth2_provider
  • rest_framework
  • polls

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

神魇的王 2024-09-13 15:57:06

应用程序目录名称必须是有效的 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.

秋凉 2024-09-13 15:57:06

我投票给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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文