Package: django-settings-custom
django-settings-customA Django interactive command for configuration file generation.Getting ItThe project is on PyPI (https://pypi.org/project/django-settings-custom/)pip install django-settings-customInstalling ItTo enabledjango_settings_customin your project you need to add it toINSTALLED_APPSin your projectssettings.pyfile:INSTALLED_APPS = (
    ...
    'django_settings_custom',
    ...
)Using ItCreate a template for your target conf.ini like[DATABASE]NAME={ USER_VALUE }HOST={ USER_VALUE }PORT={ USER_VALUE }[DATABASE_CREDENTIALS]USER={ USER_VALUE }PASSWORD={ ENCRYPTED_USER_VALUE }[DJANGO]KEY={ DJANGO_SECRET_KEY }# A constant field[LDAP]URL='ldaps://myldap'Configure in Django settingsAddsettings.pyfileSETTINGS_TEMPLATE_FILE='PATH_TO_YOUR_TEMPLATE_CONFIGURATION_FILE'SETTINGS_FILE_PATH='TARGET_FOR_CONFIGURATION_FILE'Launch in command linepython manage.py generate_settingsOr all in command linepython manage.py generate_settings path/to/template/settings.ini target/path/of/settings.iniResultsThe command ask user to fill missing values from template:[user@localhost a_project]$ ./manage.py generate_conf
** Configuration file generation: **

** Configuration file generation: **
Do you want to generate the secret key for Django ? (Y/n) : y
Django secret key generated

** Enter values for configuration file content **

Value for [DATABASE] NAME: database_name
Value for [DATABASE] HOST: database_host
Value for [DATABASE] PORT: 900
Value for [DATABASE_CREDENTIALS] USER: my_user
Value for [DATABASE_CREDENTIALS] PASSWORD (will be encrypted):

Writing file at /home/user/a_project/conf.ini:
Configuration file successfully generated.
[user@localhost a_project]$It generates the file /home/user/a_project/conf.ini:[DATABASE]NAME=database_nameHOST=database_hostPORT=900[DATABASE_CREDENTIALS]USER=my_userPASSWORD=JbAwLj5Zwz8lMrvcUZq5sP/v6eaUFY5E7U8Fmg63vxI=# A constant field[LDAP]URL='ldaps://monldap'[DJANGO]KEY=w)r13ne4=id9_8xdojir)3)%%5m3r$co#jwj_)4d*_%%!0+f#sroAnd to decrypt values in your code (in settings.py for example), you may usedjango_settings_custom.encryption.decrypt:importconfigparserfromdjango_settings_customimportencryptionconfig=configparser.RawConfigParser()config.read(SETTINGS_FILE_PATH)database_password=encryption.decrypt(config.get('DATABASE_CREDENTIALS','PASSWORD'))To decrypt values, the function uses the django SECRET_KEY (must be set before).MiscellaneousIf you don't want to use Django settingsIf you don't want to add specific variables to your Django settings file, you can inheritgenerate_settings.Commandto specify command options :fromdjango_settings_custom.management.commandsimportgenerate_settingsclassCommand(generate_settings.Command):settings_template_file='The/settings/template/file_path.ini'settings_file_path='The/target/settings/file_path.ini'Adding custom tagTo add a custom tag, you can inheritgenerate_settings.Commandand override the methodget_value:importrandomfromdjango_settings_custom.management.commandsimportgenerate_settingsclassCommand(generate_settings.Command):defget_value(self,section,key,value_type):ifvalue_type=='RANDOM_VALUE':returnrandom.uniform(0,100)returnsuper(Command,self).get_value(section,key,value_type)Or a little more complex example :fromdjango.core.management.baseimportCommandErrorfromdjango_settings_custom.management.commandsimportgenerate_settingsclassCommand(generate_settings.Command):defget_value(self,section,key,value_type):int_less_10=value_type=='INT_LESS_THAN_10'ifint_less_10:value_type='USER_VALUE'value=super(Command,self).get_value(section,key,value_type)ifint_less_10:try:value=int(value)ifvalue>=10:raiseCommandError('This field needs an int less than 10.')exceptValueError:raiseCommandError('This field needs an int.')returnvalueDocumentation