python - What file format to use for Django configuration which can be frequently updated using Django forms -
i have django application need configuration file.
i want key value pairs in there, values can updated using django form fields.
which 1 best file format, read , write easy (user can update values using django form).
i have value below:
<key_max_range>=**<value_max_range>**
the easiest thing serialize json or yaml. however, if want more human-readable format more strictly set of key-value pairs, might use configparser module. reads , writes ini-style configuration files, this:
[section] key = value
here example of writing out configuration file based on form's cleaned_data
:
in [39]: configparser import safeconfigparser in [40]: cleaned_data = {'foo': 'bar', 'bob': 'ann'} in [41]: config = safeconfigparser() in [42]: config.add_section('my_form') in [43]: field, value in cleaned_data.iteritems(): ....: config.set('my_form', field, value) ....: in [44]: open('example.cfg', 'w') config_file: ....: config.write(config_file) ....: in [45]: cat example.cfg [my_form] bob = ann foo = bar
Comments
Post a Comment