小编Shi*_*nki的帖子

嵌入的 pdf 文件未在 Django 中显示

我试图在 django 项目中使用显示照片和 pdf 文件,<embed>但 pdf 文件没有显示这是我正在做的这是查看功能

@login_required
def view_documents(request):
    students = Student.objects.filter(user=request.user)
    return render(request, 'student/view_documents.html',{'students':students})
Run Code Online (Sandbox Code Playgroud)

然后我在模板中使用 for 标签

{% for student in students %}
#lines of code
{% endfor %}
Run Code Online (Sandbox Code Playgroud)

并显示我使用过的pdf文件

<embed src="{{student.adhar_card_pdf.url}}" width="800px" height="400px" type="application/pdf"/>
Run Code Online (Sandbox Code Playgroud)

但它显示某种错误,例如 localhost 拒绝连接 我也使用了 iframe

 <iframe src="{{student.adhar_card_pdf.url}}" style="width:718px; height:700px;" frameborder="0"></iframe>
Run Code Online (Sandbox Code Playgroud)

但图像使用相同的代码在浏览器中显示,没有任何错误

<embed src="{{student.photo_jpg.url}}" width="230px" height="250px" />
Run Code Online (Sandbox Code Playgroud)

为什么pdf文件不显示?请提前帮助我,谢谢。编辑:在控制台中显示 -- 拒绝在框架中显示 '',因为它将 'X-Frame-Options' 设置为 '拒绝'。 这就是它显示pdf的方式

html python embed django iframe

6
推荐指数
1
解决办法
2140
查看次数

标签 统计

django ×1

embed ×1

html ×1

iframe ×1

python ×1