From 665bff7bc13fd627e39b333cceebc01321d05307 Mon Sep 17 00:00:00 2001 From: Nikolay Kiryanov Date: Sat, 25 Jul 2026 18:09:41 +0300 Subject: [PATCH] Fix app config base class being silently ignored MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit App configs from `manage.py startapp` have never been applied. The generated subclass imports the base — Django finds two AppConfigs in `apps.py`, neither marked default, and quietly falls back to a plain one. `default = False` on the base and `default = True` in the template fix it. --- .../src/.django-app-template/apps.py-tpl | 1 + {{ cookiecutter.name }}/src/app/apps.py | 8 ++++++-- {{ cookiecutter.name }}/src/app/base_config.py | 12 ++++++++---- {{ cookiecutter.name }}/src/app/conf/i18n.py | 2 -- {{ cookiecutter.name }}/src/users/apps.py | 9 +++++++++ 5 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 {{ cookiecutter.name }}/src/users/apps.py diff --git a/{{ cookiecutter.name }}/src/.django-app-template/apps.py-tpl b/{{ cookiecutter.name }}/src/.django-app-template/apps.py-tpl index 865202f2..cb268f45 100644 --- a/{{ cookiecutter.name }}/src/.django-app-template/apps.py-tpl +++ b/{{ cookiecutter.name }}/src/.django-app-template/apps.py-tpl @@ -2,4 +2,5 @@ from app.base_config import AppConfig class {{ camel_case_app_name }}Config(AppConfig): + default = True name = "{{ app_name }}" diff --git a/{{ cookiecutter.name }}/src/app/apps.py b/{{ cookiecutter.name }}/src/app/apps.py index efd3843c..b591ade0 100644 --- a/{{ cookiecutter.name }}/src/app/apps.py +++ b/{{ cookiecutter.name }}/src/app/apps.py @@ -1,5 +1,9 @@ -from django.apps import AppConfig as DjangoAppConfig +from django.utils.translation import gettext_lazy as _ +from app.base_config import AppConfig as BaseAppConfig -class AppConfig(DjangoAppConfig): + +class AppConfig(BaseAppConfig): + default = True name = "app" + verbose_name = _("Application") diff --git a/{{ cookiecutter.name }}/src/app/base_config.py b/{{ cookiecutter.name }}/src/app/base_config.py index 84f14dba..3a8df185 100644 --- a/{{ cookiecutter.name }}/src/app/base_config.py +++ b/{{ cookiecutter.name }}/src/app/base_config.py @@ -5,16 +5,20 @@ class AppConfig(BaseAppConfig): - """Default App configuration template. Import app.signals.handers. + """Default App configuration template. Imports app.signals.handlers. - We do not recomend you to use django signals at all. + We do not recommend you to use django signals at all. Check out https://lincolnloop.com/blog/django-anti-patterns-signals/ if you know nothing about that. - Allthough, if you wish to use signals, place handlers to the `signals/handlers.py`: - your code be automatically imported and used. + Although, if you wish to use signals, place handlers to the `signals/handlers.py`: + your code will be automatically imported and used. """ + # Django's `apps.py` scan sees two configs — yours and this one, pulled in by your import. + # `False` here, `True` in your subclass: otherwise Django silently takes a plain AppConfig. + default = False + def ready(self) -> None: """Import a module with handlers if it exists to avoid boilerplate code.""" with contextlib.suppress(ModuleNotFoundError): diff --git a/{{ cookiecutter.name }}/src/app/conf/i18n.py b/{{ cookiecutter.name }}/src/app/conf/i18n.py index 040ac52f..951e3de3 100644 --- a/{{ cookiecutter.name }}/src/app/conf/i18n.py +++ b/{{ cookiecutter.name }}/src/app/conf/i18n.py @@ -6,5 +6,3 @@ LOCALE_PATHS = [ SRC_DIR / ".locale", ] - -USE_i18N = True diff --git a/{{ cookiecutter.name }}/src/users/apps.py b/{{ cookiecutter.name }}/src/users/apps.py new file mode 100644 index 00000000..a62a6eb0 --- /dev/null +++ b/{{ cookiecutter.name }}/src/users/apps.py @@ -0,0 +1,9 @@ +from django.utils.translation import gettext_lazy as _ + +from app.base_config import AppConfig as BaseAppConfig + + +class AppConfig(BaseAppConfig): + default = True + name = "users" + verbose_name = _("Users")