This question has been asked earlier: What is the purpose of apps.py in Django 1.9?
Application configuration objects store metadata for an application. Some attributes can be configured in AppConfig subclasses. Others are set by Django and read-only.
However, what does it mean by metadata for application? Is it limited only to those AppConfig
metadata:name
, verbose_name
, path
, label
, module
, models_module
?
Or does it make sense to extends beyonds the predefined metadata, especially for Application Specific metadata, for example in blog
apps we have a date format configuration, usually defined as follows:
# File: settings.py
BLOG = {
'DATE_FORMAT': 'ddMMYYY',
}
At which it is being used as follow:
# File: blog/<...>.py
from django.conf import settings
date_format = settings.BLOG['DATE_FORMAT']
On contrary, we could move this configuration into blog/apps.py
as BlogConfig
?
class BlogConfig(AppConfig):
name = 'blog'
verbose_name = 'Awesome Blog'
date_format = 'ddMMYYYY'
So that throughout the code in the application, date_format
is being used by:
# File: blog/<...>.py
from django.apps import apps
date_format = apps.get_app_config('blog').date_format
It sounds to me that settings.py
is project settings, but not an application settings. Thus it is more sounds to put all application settings inside apps.py
then settings.py
. So, is this a valid assumption/argument/convention for me to put application configuration inside apps.py
instead of settings.py
?