def generate_word_report(request):
if request.method == 'POST':
doc = Document()
data = json.loads(request.body)
form_data = data.get('formData', {})
table_list = data.get('tableData', [])
title = doc.add_heading('Sample Word Report', level=1)
title.alignment = WD_ALIGN_PARAGRAPH.CENTER
doc.add_paragraph("This is a sample Word report generated using Django and python-docx.")
doc.add_paragraph("You can add more paragraphs and formatting as needed.")
response = HttpResponse(content_type='application/vnd.openxmlformats-officedocument.wordprocessingml.document')
response['Content-Disposition'] = 'attachment; filename="sample_report.docx"'
doc.save(response)
return response
what is the problem when generates report always says content missing but if im going to remove the form_data = data.get('formData', {})
table_list = data.get('tableData', [])
the print works.