Christian, I do this in my internal and private module that depends on django-cas-ng. django-cas-ng provides default settings in an __init__.py file that predates app.py and ready. My strategy is that if you wish to depend on another app in this way, it is best to shadow it entirely. For example, django-cas-ng defines an authentication backend, CASBackend. I had an empty subclass for a long time until I needed to do something else. As Tom Forbes writes, this is a hard problem to solve.
For example, JavaScript closures have allowed npm to solve transitive dependencies in some novel ways that have introduced new problems. Another way to solve this is to have settings that use duck typing to behave like other sorts of settings. For instance, I support EC2 Secrets Manager and Django database configuration by having a DBConfig class that acts like a dict, even down to __copy__ and __deepcopy__, so that whenever Django asks for the database configuration, I can go get the secret. This frees the ops guys from restarting the app when the secret is automatically rotated. Because Python is so extensible, these things work, up to a point, but it is a hard problem. On Tue, May 7, 2019 at 5:55 PM Christian González < christian.gonza...@nerdocs.at> wrote: > > Sorry about writing, and not testing myself before: > > 2. Set a default value at import time: > > # apps.py > > from django.apps import AppConfig > from django.conf import settings > > class MyAppConfig(AppConfig): > name = 'my_app' > verbose_name = "..." > > def ready(self): > if not hasattr(settings, 'MY_SETTING'): > settings.MY_SETTING = 'my_default' > > This works. > > I have an app that has the following code in <app>Config.ready(): > > settings.WEBPACK_LOADER.update( > { > "foobar": { > "STATS_FILE": os.path.join( > settings.BASE_DIR, > "{}/frontend/webpack-stats.json".format( > os.path.abspath(os.path.dirname(__file__)) > ), > ) > } > } > ) > > And the app webpack_loader is located *after* this app in INSTALLED apps. > Within webpack-loader, the settings dict WEBPACK_LOADER inclusive "foobar" > is available. So this is kind of "solved" for me - but - it's a bit of a > hack. > > I'd really appreciate a "standard" approach from Dajngo... > > Thanks for your patience, ;-) > > Christian > > -- > Dr. Christian Gonzálezhttps://nerdocs.at > > -- > You received this message because you are subscribed to the Google Groups > "Django developers (Contributions to Django itself)" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-developers+unsubscr...@googlegroups.com. > To post to this group, send email to django-developers@googlegroups.com. > Visit this group at https://groups.google.com/group/django-developers. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-developers/3727cd68-3ed6-1366-2277-0815ae90da5c%40nerdocs.at > <https://groups.google.com/d/msgid/django-developers/3727cd68-3ed6-1366-2277-0815ae90da5c%40nerdocs.at?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To post to this group, send email to django-developers@googlegroups.com. Visit this group at https://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAFzonYZ4s65G4Nq4u4Xe2SobBzu9fe00qwVvR5H%3DJe9WH%3DDskg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.