1👍
You can use basic Python methods open()
and write()
. You can access kwargs with self.get_form()
in your View
with form_class
or similar option.
def post(self, request, *args, **kwargs):
form = self.get_form()
with open('text_file.txt', 'w') as file:
file.write(f'Field_1: {form.data["field_1"]}\n')
file.write(f'Field_2: {form.data["field_2"]}\n')
...
example ‘text_file.txt’:
Field_1: SomeValue
Field_2: another value
Field_3: 3
...
Source:stackexchange.com