我正在尝试从服务器中显示/读取pdfs,但是得到了错误。下面我附上了我的view.py。请帮我解决这个问题
views.py
from django.shortcuts import render
from django.http import HttpResponse
from .models import PDF
def pdf_view(request):
a = PDF.objects.get(id=id)
with open('a.pdf', 'rb') as pdf:
response = HttpResponse(
Django文档提供了以下ReportLab示例。 from reportlab.pdfgen import canvas
from django.http import HttpResponse
def some_view(request):
# Create the HttpResponse object with the appropriate PDF headers.
response = HttpResponse(content_type='application/pdf')
response['Content-Dispositio
我在使用python/django创建指向我目录中的pdf文档的链接时遇到了问题。html页面中的链接如下所示: <a href="pilots/12-and-Holding.pdf" target="_blank" Read Me</a> 这是一个pdf,我想在另一个页面上打开,然后可以下载。它设置的文件夹是pilots/12-and-Holding.pdf。 我哪里错了?我得到的错误是: Using the URLconf defined in scripts.urls, Django tried these URL patterns,
我只想点击一个链接,在浏览器中查看我上传到Django项目中的PDF。当然,在Django文档(https://docs.djangoproject.com/en/3.1/howto/outputting-pdf/)中关于如何创建报告并不是我想要做的事情。我不需要生成PDF,我已经有了我需要的。(这在其他答案中出现得很多。) 不走运:Render HTML to PDF in Django site (毫不奇怪,已经11年了) 或者:Django - JS : How to display the first PDF page as cover (有点惊讶这不是唯一一次出现包含pdf.js的
我收到以下错误:Reverse for 'order_pdf' with arguments '('',)' not found. 1 pattern(s) tried: ['business_plan/(?P<id>[0-9]+)/pdf/$'] 我不确定到底是什么原因造成的。 以下是模型: class Info(models.Model):
logo = models.ImageField(default='report-cover.jpg', null=Tr
基本上,我有一个冒号分隔的变量被传递到我的模板中,我想循环通过它来显示每个单独的元素。
我希望能够提取这些名称中的每一个,然后在我的模板中对它们执行逻辑。
如果我可以使用python,我会这样做(注意: file_type是我的模板中的变量):
file_type = "PDF:DOC:XLS"
for tipe in file_type.split(":"):
if tipe == "PDF":
print "<img src='pdf'/>"
elif tipe ==
在加载整个文件之前,不会显示该文件。如何在浏览器中显示进度?
from io import BytesIO
from reportlab.pdfgen import canvas
from django.http import HttpResponse
def some_view(request):
# Create the HttpResponse object with the appropriate PDF headers.
response = HttpResponse(mimetype='application/pdf')
respon
我有以下自定义表单验证:
forms.py
import os
from django.core.exceptions import ValidationError
def validate_allegato(allegato):
ext = os.path.splitext(allegato.name)[1]
valid_extensions = [ '.pdf']
if not ext.lower() in valid_extensions:
raise ValidationError(u'Unsupported file
我对Django很陌生。我有一个模型,它有两个字段,名为id (as pk)和region,我有一个页面来返回每个region.There中的对象,它们是10个区域,我需要将区域号传递给url,以便从db筛选该区域检索数据。这是我的代码:
views.py
def render_pdf_view(request, *args, **kwargs):
pk = kwargs.get('pk') *********here i need to get region from clicked button instead of pk*************
data = MyM
我今天一整天都在玩Reportlab和Django,我终于让它在这个问题的帮助下工作了,所以今天早些时候.输出现在正像预期的那样被生成。但是,当输出以PDF格式生成时,我无法获得要显示的图像。什么都不呈现。
我尝试过调查我的URL,我的绝对URL在我的settings.py文件中,什么都没有。我注意到我无法获得我的模板来获取我的任何静态设置,然而我的项目的其余部分在相同的引用中工作得很好。我也发现了类似的问题,但似乎无法确定实际的修复.
我的utils.py文件。
from io import BytesIO
from django.http import HttpResponse
from
在django-easy pdf中有没有一种方法可以在打印的每一页上包含表格标题?
<table>
<tr>
<th> First Name </th><th> Last Name</th> <!--I want this on each page of pdf -->
</tr>
{% for employee in employees %}
<tr>
<td> {{ employee.first_name}} <