How to save Django application settings in a database or change them on the fly?

Does anyone have a suggestion on how to create a system that allows me to change settings on the fly? For example, I have a text box that users can fill out, and now it has a maximum character limit of 1000. Someday I will want to change it to 500 or 2000 or something else. Therefore, I do not want to limit myself to the model itself, so as not to miss the nightmare of database backup, run syncdb, re-import DB, such a nightmare to change a simple value. I would rather check out Javascript or views.py code for character length.

if (length > value_stored_somewhere) throw error message 

I thought I could just put these values ​​in settings.py or maybe in a separate local-settings.py file, but that means if I want to change the value that I will need to restart, right? Or I may be wrong, so please tell me if I am wrong.

I thought that the ideal way to do this would be to set the settings in the database so that administrators can change the values ​​on the fly without touching any .py files. I looked at django-dbsettings, but there seemed to be no activity there.

Please give me suggestions and solutions. Thank you very much!

+4
source share
1 answer

You are right with all your assumptions. You need to restart the application if you want to change the settings (in any settings file). Right now there is no way to "change settings on the fly." There are many reusable applications that run Live Settings . You might try one of them. Keep in mind that even if you change the settings on the fly, you will not change the behavior in Django (since Django or other applications directly use the internal settings). However, for a user application or project, this is a good approach.

+3
source

All Articles