我正在嘗試在 Django 中將 html 呈現為 pdf 每月報告,該報告按月從資料庫中獲取資料。我需要將 html 頁面上選定的月份發送到創建 Pdf 的類。我怎樣才能做到這一點?
我的觀點類:
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>
謝謝 !
uj5u.com熱心網友回復:
首先創建一個簡單的表單,將月份資料發送到您的視圖
<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')
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/400629.html
