I'm trying in Django to render from html to pdf a monthly report that takes data from a database by month. I need to send the selected month on the html page to the class that creates the Pdf. How can I do that?
My view class :
class view_pdf_monthly_report(View):
def get(self, request, *args, **kwargs):
push = {'month':month}
pdf = render_to_pdf('home/pdf_monthly_inquiries_report.html', push)
return HttpResponse(pdf, content_type='application/pdf')
My html: how can I send the month from here?
<div >
<a href="{% url 'view_pdf_monthly_report'%}" target="_blank">View PDF</a>
</div>
Thanks !
CodePudding user response:
first create a simple form which will send month data to your view
<div >
<form action="{% url 'view_pdf_monthly_report'%}" method="get">
<input type="hidden" value="{{month}}" name="month">
<button type="sumbit">View PDF</button>
</form>
</div>
and then inside your views
class view_pdf_monthly_report(View):
def get(self, request, *args, **kwargs):
month = request.GET.get('month')
push = {'month':month}
pdf = render_to_pdf('home/pdf_monthly_inquiries_report.html', push)
return HttpResponse(pdf, content_type='application/pdf')