2017-04-13 30 views
0

我使用django-easy-pdf時加載和我有以下看法:Django的 - 圖像不使用PDF查看

class PrescriptionView(PDFTemplateView): 
    template_name = 'meds/prescription.html' 
    context_object_name = 'meds' 
    model = Medicament 

    def get_queryset(self): 
     ids = map(int, self.kwargs['selected'].split(",")) 
     return Medicament.objects.filter(id__in=ids) 

    def get_context_data(self, **kwargs): 
     context = super(PrescriptionView, self).get_context_data(pagesize="A5", title="Ordonnance", **kwargs) 
     return context 

而且我有以下的HTML頁:

{% load staticfiles %} 
<html> 
    <head> 
     <meta charset="UTF-8"> 
     <style> 
      @page { size: A5; 
       @frame headerLogo { 
        top: 23mm; 
        left: 20mm; 
        width: 50mm; 
        height: 24mm; 
        -pdf-frame-content: headerLogo; 
       } 
      } 
     </style> 
    </head> 
    <body> 
    <div id="headerLogo"> 
     <img src="{% static 'img/banner.png' %}"> 
    </div> 
</body> 

但旗幟.png圖片不加載,我不斷收到以下錯誤:

missing explicit frame definition for content or just static frames 

getFile '/static/img/banner.png' None '/home/nids/cabin' 
'<div id="headerLogo"> <img src="/static/img/banner.png"/> </div>' 
Traceback (most recent call last): 
    File "/home/nids/cabin/dentist/lib/python3.5/site-packages/xhtml2pdf/context.py", line 828, in _getFileDeprecated 
    nv = self.pathCallback(name, relative) 
    File "/home/nids/cabin/dentist/lib/python3.5/site-packages/easy_pdf/rendering.py", line 35, in fetch_resources 
    path = os.path.join(settings.STATIC_ROOT, uri.replace(settings.STATIC_URL, "")) 
    File "/home/nids/cabin/dentist/lib/python3.5/posixpath.py", line 89, in join 
    genericpath._check_arg_types('join', a, *p) 
    File "/home/nids/cabin/dentist/lib/python3.5/genericpath.py", line 143, in _check_arg_types 
    (funcname, s.__class__.__name__)) from None 
TypeError: join() argument must be str or bytes, not 'NoneType' 
Need a valid file name! 
'<img src="/static/img/banner.png"/>' 
line 0, msg: missing explicit frame definition for content or just static frames, fragment: 
line 0, msg: getFile %r %r %r, fragment: '<div id="headerLogo"> <img src="/static/img/banner.png"/> </div>' 
line 0, msg: Need a valid file name!, fragment: '<img src="/static/img/banner.png"/>' 

我沒有問題,我的靜態文件在其他v除了這個PDF格式之外

回答

-1

大約10個小時試圖解決這個問題,並且OH MA GOD,它是解決的。 問題很簡單 - 重新安裝這個包

1.pip install --pre xhtml2pdf。

2.pip install --pre reportlab。

3.pip install django-easy-pdf。

只記得之前卸載這個命令。 還有一件事,試着在純html上設置img標籤的高度和寬度。