Reputation: 93
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
Upvotes: 4
Views: 3515
Reputation: 151
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.
Upvotes: 15