What is the purpose of apps.py in Django 1.9? -


i went on alpha release notes django 1.9 , saw startapp management command now adds apps.py file.

what's purpose of file? startapp documentation didn't provide more information.

purpose of apps.py file:

this file created user include application configuration app. using this, can configure of attributes of application.

from application configuration documentation:

application configuration objects store metadata application. attributes can configured in appconfig subclasses. others set django , read-only.

example docs:

lets you’re creating pluggable app called "rock ’n’ roll", provide proper name admin can following:

in rock_n_roll app, create rocknrollconfig appconfig class.

#rock_n_roll/apps.py django.apps import appconfig  class rocknrollconfig(appconfig): # our app config class     name = 'rock_n_roll'     verbose_name = "rock ’n’ roll" 

we can make application load appconfig subclass default specifying default_app_config in rock_n_roll/__init__.py file.

# rock_n_roll/__init__.py     default_app_config = 'rock_n_roll.apps.rocknrollconfig' 

doing cause rocknrollconfig used when installed_apps contains 'rock_n_roll'. allows make use of appconfig features without requiring our users update installed_apps setting.


Comments