【发布时间】:2020-07-18 09:52:25
【问题描述】:
我试图在 django 项目中使用 <embed> 显示照片和 pdf 文件,但 pdf 文件未显示
这是我在做什么
这是视图函数
@login_required
def view_documents(request):
students = Student.objects.filter(user=request.user)
return render(request, 'student/view_documents.html',{'students':students})
然后我在模板中使用了标签
{% for student in students %}
#lines of code
{% endfor %}
并显示我使用过的 pdf 文件
<embed src="{{student.adhar_card_pdf.url}}" width="800px" height="400px" type="application/pdf"/>
但它显示了某种错误,例如 localhost 拒绝连接 我也用过 iframe
<iframe src="{{student.adhar_card_pdf.url}}" style="width:718px; height:700px;" frameborder="0"></iframe>
但是图像在浏览器中显示使用相同的代码没有任何错误
<embed src="{{student.photo_jpg.url}}" width="230px" height="250px" />
为什么不显示pdf文件??请帮我 提前谢谢。 已编辑:在控制台中显示-拒绝在框架中显示“”,因为它将“X-Frame-Options”设置为“拒绝”。 This is how it is displaying pdf
【问题讨论】:
-
打开您的浏览器开发工具,告诉我们您看到的确切错误。查看网络选项卡并检查它试图获取的 url。查看您的服务器控制台并告诉我们您在那里看到的内容。
-
在控制台中显示:拒绝在框架中显示“
”,因为它将“X-Frame-Options”设置为“拒绝”。
标签: python html django iframe embed