Is there a naming convention for Django apps

DjangoNaming ConventionsDjango Apps

Django Problem Overview


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?

Django Solutions


Solution 1 - Django

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.

Solution 2 - Django

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

Solution 3 - Django

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.

Solution 4 - Django

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMatthew RankinView Question on Stackoverflow
Solution 1 - DjangothraxilView Answer on Stackoverflow
Solution 2 - DjangoJamil NoydaView Answer on Stackoverflow
Solution 3 - DjangoIgnacio Vazquez-AbramsView Answer on Stackoverflow
Solution 4 - DjangoGuardView Answer on Stackoverflow