T
T
thaessaep2020-09-01 09:02:02
Flask
thaessaep, 2020-09-01 09:02:02

How to display a pdf file on a new page?

Good afternoon.

The essence of the question is this: when a user clicks on a button, you need to open a new browser tab and display a pdf file on it, without changing the page on which this button was clicked.

PS I tried to redirect the user to a new url through redirect, and there already open a new tab. Through this method, a POST request is sent, but for some reason the new url accepts GET and therefore I cannot output the pdf file only if the html template.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
pcdesign, 2020-09-01
@thaessaep

Or I didn't understand something. But this seems to be done at the html level with target="_blank"

<a href="http://example.com" target="_blank">go</a>

In Flask, you can also do this:
from flask import  send_file
return send_file(report_file_pdf, as_attachment=True)

R
Roman Mirilaczvili, 2020-09-01
@2ord

An appropriate Content-Disposition HTTP header must be specified

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question