Django3 Refresh/reload configuration settings during runtime

1k views Asked by At

I am using Django3 application, configuration settings.py were loaded during application startup. Consider an application were running in an production if any of the token expires to regenerate the token, need to get an configurations from settings.py during runtime. I got an exception if token has expires. How should I reload/refresh the configuration settings during runtime only if token expires.

1

There are 1 answers

0
michjnich On

I actually think you're trying to solve the wrong problem here, but let me address your main question first.

You can get att the settings info from your code by simply doing:

from django.conf import settings

Then you can access settings.<setting val> - eg. if settings.DEBUG: in your code.

Now, when you talk about tokens, I guess you mean user tokens to indicate they have a valid session (by "user" I would also mean API logins), which may have timed out.

settings.py holds information that is relevant for the Django session itself - i.e. the server-side process. It does not hold information about the current user, so I can see no reason you would need to reload this at any point. It's loaded when the django process is started (either via runserver, or gunicorn or whatever). If you find yourself needing to reload settings.py when Django is already up and running, then you almost certainly have something in settings that should be handled elsewhere.