Hi,
I have some problems generating en downloading a Word file.
This is the error message I am getting:
File "viktor\external\word.pyx", line 182, in viktor.external.word.render_word_file
File "viktor\external\word.pyx", line 205, in viktor.external.word._create_fill_word_file_request_body
File "C:\Program Files\Python38\lib\json\__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
File "C:\Program Files\Python38\lib\json\encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "C:\Program Files\Python38\lib\json\encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "C:\Program Files\Python38\lib\json\encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type type is not JSON serializable
And this is a part of the code I am using:
def generate_report(params):
entity_folder_path = Path(__file__).parent # entity_type_a
template_path = entity_folder_path.parent / 'template_calc_report.docx'
components = [
WordFileTag('project_name', 'test'),
WordFileTag('project_number', '01234456'),
WordFileTag('report_date', date),
WordFileTag('report_time', time),
]
with open(template_path, 'rb') as template:
word_file = render_word_file(template, components)
return word_file
def download_file(self, params, **kwargs):
return DownloadResult(generate_report(params), 'report.docx')