Restituzione di una risposta PDF in Django
-
11-11-2019 - |
Domanda
Sto facendo una domanda molto simile a Questo. Sto creando un PDF utilizzando Wkhtmltopdf su un server Ubuntu in Django.
from tempfile import *
from subprocess import Popen, PIPE
tempfile = gettempdir()+"/results.pdf"
papersize = 'Tabloid'
orientation = 'Landscape'
command_args = "wkhtmltopdf -O %s -s %s -T 0 -R 0 -B 0 -L 0 http://pdfurl %s" %(orientation, papersize, tempfile)
popen = Popen(command_args, stdout=PIPE, stderr=PIPE)
pdf_contents = popen.stdout().read()
popen.terminate()
popen.wait()
response = HttpResponse(pdf_contents, mimetype='application/pdf')
return response
Questo mi dà un errore "nessun file o directory" sulla riga Popen = Popen .... Quindi ho cambiato quella linea in
popen = Popen(["sh", "-c", command_args], stdout=PIPE, stderr=PIPE)
E ora ricevo un errore "'file' non è richiamabile" sulla riga pdf_contents = ....
Ho anche provato ad aggiungere .comunicate () alla linea popen = ... ma non riesco a individuare l'output PDF in quel modo. Dovrei aggiungere che digitare la riga Command_args nella riga di comando crea bene un PDF. Qualcuno può indicarmi nella giusta direzione?
Nessuna soluzione corretta
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow