user8445949
user8445949

Reputation:

UPPER_CASE_WITH_UNDERSCORES in Django

in Django, almost all the variables' naming style is UPPER_CASE_WITH_UNDERSCORES, for instance:

INSTALLED_APPS = [
    ]
MIDDLEWARE_CLASSES = [

]

and so on...

what's the conventions it follows?

Upvotes: 1

Views: 947

Answers (4)

Fathima Shaibal
Fathima Shaibal

Reputation: 15

Django setting required uppercase letter for custom-defined settings variables These are certain rules in Django for creating our own settings Creating your own settings There’s nothing stopping you from creating your own settings, for your own Django apps, but follow these guidelines: Setting names must be all uppercase. Don’t reinvent an already-existing setting. For settings that are sequences, Django itself uses lists, but this is only a convention. Please have a look at Django documentation - https://docs.djangoproject.com/en/3.0/topics/settings/

Django itself follows that rules and Naming convention in python like splits with the underscores are from pep8.

Upvotes: 0

knbk
knbk

Reputation: 53679

In addition to being constants and following PEP8, these constants are Django settings. Settings are defined in a settings module, and Django exposes an object, django.conf.settings, that proxies attributes in this module. The proxy object only exposes settings that are all uppercase.

So if you want your settings to be available on django.conf.settings, using uppercase variable names is not just a convention, it's required.

Upvotes: 6

Jahongir Rahmonov
Jahongir Rahmonov

Reputation: 13743

It follows PEP 8.

The letters are upper case because they are constants. And the underscore is a usual python naming convention.

UPPER_CASE_WITH_UNDERSCORES

Upvotes: 1

Sayse
Sayse

Reputation: 43300

Pep8, its common across most python and PyCharm helps to enforce it.

In particular, this is the rule for constants

Constants are usually defined on a module level and written in all capital letters with underscores separating words. Examples include MAX_OVERFLOW and TOTAL.

Upvotes: 2

Related Questions