Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

232
Views
Django convierte la página actual a PDF al hacer clic en el botón

Estoy usando Django 1.10 y Python 3.4 en Windows. Configuré pdfkit y funciona perfectamente desde la línea de comandos. Quiero usarlo en el sitio en un botón para devolver la página actual como un archivo adjunto en pdf sin redirigir a ningún lado (si es posible). La página para convertir es un informe que utiliza una fecha especificada por el usuario como URL.

Actualmente, el botón redirige agregando la URL actual con "?mybtn=Generate+PDF#"

He visto algunas soluciones usando jQuery o javascript, pero realmente solo conozco bien Python. Los aprenderé eventualmente, pero por ahora me gustaría una solución más rápida en la que entienda lo que está pasando.

vistas.py

 class FlashReport(generic.View): template_name = "reports_flash_report.html" def get(self, request, year, month, day): report_data = get_flash_report_data(int(year),int(month),int(day)) return render(request, 'reports_flash_report.html', report_data) def generate_PDF(request): path = request.get_full_path() pdf = pdfkit.from_url(path, False) response = HttpResponse(pdf, content_type='application/pdf') response['Content-Disposition'] = 'attachment; filename="flash_report.pdf"' return response

informes_flash_report.html

 <div> <form action="" method="get"> <input type="submit" class="btn" value="Generate PDF" name="mybtn" /> </form> </div>

urls.py

 url(r'^flash_report/(?P<year>[0-9]{4})-(?P<month>[0-9]{2})-(?P<day>[0-9]{2})/$', views.FlashReport.as_view(), name="flash_report"),
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!