this is the code:
def render_to_pdf(template_src, context_dict):
template = get_template(template_src)
context = Context(context_dict)
html = template.render(context)
result = StringIO.StringIO()
pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("UTF-8")), result)
if not pdf.err:
return HttpResponse(result.getvalue(), mimetype='application/pdf')
return HttpResponse('We had some errors<pre>%s</pre>' % escape(html))
I use django 1.7 and the error is
init() got an unexpected keyword argument 'mimetype'
Request Method: GET Request URL: http://127.0.0.1:8000/admin/amministrazione/ddts/stampa/1/ Django Version: 1.7.7 Exception Type: TypeError Exception Value:
init() got an unexpected keyword argument 'mimetype'
Exception Location: /home/stefano/.virtualenvs/company2/local/lib/python2.7/site-packages/django/http/response.py in init, line 318 Python Executable: /home/stefano/.virtualenvs/company2/bin/python Python Version: 2.7.6
Replace:
return HttpResponse(result.getvalue(), mimetype='application/pdf')
with
return HttpResponse(result.getvalue(), content_type='application/pdf')
I had this problem too, and this change helped.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With