2017-09-03 8 views
1

: 나는 그것이 차이를 만들하지만 낯선 일이 일어난 원인 어쨌든 그것을 시도 것이라고 생각하지 않았다 알고django_xhtml2pdf를 django 1.11과 함께 사용하기 "오류 : context는 Context가 아닌 dict이어야합니다." 코멘트 중 하나 당

providers = Provider.objects.all() 
context = { 'providers':providers} 

: 나는 내 코드를 변경했다. 오류가 모듈 내에서 장고 내 버전에서 실행되는 걱정입니다.

나는이에 대한 다른 답변을 참조했고, 난 그냥 여기에 기록 된 것을 사용하고 있기 때문에 그것은 나를 혼동 :

https://spapas.github.io/2015/11/27/pdf-in-django/#django-integration

를 작업 할 수있는 django_xhtml2pdf 물건을 얻기 위해. 내보기 등입니다 :

Traceback (most recent call last): 
    File "D:\Python27\lib\site-packages\django\core\handlers\exception.py", line 41, in inner 
    response = get_response(request) 
    File "D:\Python27\lib\site-packages\django\core\handlers\base.py", line 249, in _legacy_get_response 
    response = self._get_response(request) 
    File "D:\Python27\lib\site-packages\django\core\handlers\base.py", line 187, in _get_response 
    response = self.process_exception_by_middleware(e, request) 
    File "D:\Python27\lib\site-packages\django\core\handlers\base.py", line 185, in _get_response 
    response = wrapped_callback(request, *callback_args, **callback_kwargs) 
    File "D:\Programming\web\ipa_django\mysite\ipaswdb\views.py", line 312, in providers_plain_old_view 
    result = generate_pdf('ipaswdb/provider/providers_plain_old_view.html', file_object=resp, context=context) 
    File "D:\Python27\lib\site-packages\django_xhtml2pdf\utils.py", line 62, in generate_pdf 
    generate_pdf_template_object(tmpl, file_object, context) 
    File "D:\Python27\lib\site-packages\django_xhtml2pdf\utils.py", line 39, in generate_pdf_template_object 
    html = template_object.render(Context(context)) 
    File "D:\Python27\lib\site-packages\django\template\backends\django.py", line 64, in render 
    context = make_context(context, request, autoescape=self.backend.engine.autoescape) 
    File "D:\Python27\lib\site-packages\django\template\context.py", line 287, in make_context 
    raise TypeError('context must be a dict rather than %s.' % context.__class__.__name__) 
TypeError: context must be a dict rather than Context. 
"GET /ipaswdb/provider_roster/ HTTP/1.1" 500 86485 

내 말은 저를 원한다 : 지금 알고

def providers_plain_old_view(request): 
    resp = HttpResponse(content_type='application/pdf') 
    context = { 
     'providers': Provider.objects.all() 
    } 

    result = generate_pdf('ipaswdb/provider/providers_plain_old_view.html', file_object=resp, context=context) 
    return result 

가 장고 내가 사용하고 1.11.14 나쁜이지만, 오류를 수정하는 방법을 모르고 없다 최신 django 버전에서 generate_pdf 함수를 다른 방식으로 호출 하시겠습니까?

답변

2

주요 문제는 에러 출력 라인

File "D:\Python27\lib\site-packages\django_xhtml2pdf\utils.py", line 39, in generate_pdf_template_object 
html = template_object.render(Context(context)) 

에있다. 이것은 django-xhtml2pdf 패키지가 1.11의 최신 버전이 아닌 문제입니다. 렌더링 호출은 1.11 노트 섹션 django.template.loader https://docs.djangoproject.com/en/1.11/ref/templates/upgrading/ 로 업그레이드에 따라

html = template_object.render(context) 

html = template_object.render(Context(context)) 

변경되었습니다.

사용자가 버그 신고를 제출하거나 패키지가 제공하는 기능을 구현하여 기다릴 수도 있습니다 .Vis.py