Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

application/pdf pisa __init__() got an unexpected keyword argument 'mime type'

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

like image 467
Stefano Ruzza Avatar asked Dec 08 '22 03:12

Stefano Ruzza


1 Answers

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.

like image 122
Svyat Avatar answered Dec 11 '22 10:12

Svyat