Button download pdf sur django
Bonjour,
je tente de creer sur mon app django un bouton download pdf
mais j obtiens ceci comme error
AttributeError at /views.download_my_pdf
'str' object has no attribute 'read'
html
views.py
qui peut m aider ? merci
je tente de creer sur mon app django un bouton download pdf
mais j obtiens ceci comme error
AttributeError at /views.download_my_pdf
'str' object has no attribute 'read'
html
<a class="btn btn-primary" href="{% url 'download_pdf' %}" role="button">Download pdf</a>
views.py
def download_pdf(request): filename = 'faults.pdf' content = FileWrapper(filename) response = HttpResponse(content, content_type='application/pdf') response['Content-Length'] = os.path.getsize(filename) response['Content-Disposition'] = 'attachment; filename=%s' % 'faults.pdf' return response
qui peut m aider ? merci
Configuration: Windows / Chrome 98.0.4758.102
A voir également:
- Django pdf
- Lire le coran en français pdf - Télécharger - Histoire & Religion
- Save as pdf office 2007 - Télécharger - Bureautique
- Télécharger dictionnaire larousse pdf gratuit - Télécharger - Dictionnaires & Langues
- Notices gratuites pdf - Guide
- Pdf creator - Télécharger - PDF
1 réponse
Bonjour,
En admetatnt que la classe
Bonne chance
En admetatnt que la classe
FileWrapperque tu utilises soit celle-ci, il faut lui passer en paramètre le descripteur de fichier associé au fichier obtenu une fois le fichier ouvert.
filename = 'faults.pdf' with open(filename, "r") as f: content = FileWrapper(f)
Bonne chance