Is there a naming convention for Django apps

后端 未结 4 2159
孤独总比滥情好
孤独总比滥情好 2020-12-12 22:57

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_
相关标签:
4条回答
  • 2020-12-12 23:48

    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.

    0 讨论(0)
  • 2020-12-12 23:50

    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.

    0 讨论(0)
  • 2020-12-12 23:54

    My votes for 1 and 3, but you can check several popular apps: http://www.django-cms.org/ http://geodjango.org/

    0 讨论(0)
  • 2020-12-13 00:01

    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

    0 讨论(0)
提交回复
热议问题