简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM