将参数发送到pdf的渲染函数
Sending a parameter to the render function of pdf
我正在尝试在 Django 中将 html 呈现为 pdf 月度报告,该报告按月从数据库中获取数据。
我需要将 html 页面上选定的月份发送到创建 Pdf 的 class。我该怎么做?
我的观点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')
我的html:如何从这里发送月份?
<div class="text-center">
<a class="btn btn-info" href="{% url 'view_pdf_monthly_report'%}" target="_blank">View PDF</a>
</div>
谢谢!
首先创建一个简单的表单,它将月份数据发送到您的视图
<div class="text-center">
<form action="{% url 'view_pdf_monthly_report'%}" method="get">
<input type="hidden" value="{{month}}" name="month">
<button class="btn btn-info" type="sumbit">View PDF</button>
</form>
</div>
然后进入你的视野
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')
我正在尝试在 Django 中将 html 呈现为 pdf 月度报告,该报告按月从数据库中获取数据。 我需要将 html 页面上选定的月份发送到创建 Pdf 的 class。我该怎么做?
我的观点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')
我的html:如何从这里发送月份?
<div class="text-center">
<a class="btn btn-info" href="{% url 'view_pdf_monthly_report'%}" target="_blank">View PDF</a>
</div>
谢谢!
首先创建一个简单的表单,它将月份数据发送到您的视图
<div class="text-center">
<form action="{% url 'view_pdf_monthly_report'%}" method="get">
<input type="hidden" value="{{month}}" name="month">
<button class="btn btn-info" type="sumbit">View PDF</button>
</form>
</div>
然后进入你的视野
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')