Shi*_*nki 6 html python embed django iframe
我试图在 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的方式
小智 8
X_FRAME_OPTIONS = 'SAMEORIGIN'
Run Code Online (Sandbox Code Playgroud)
将上面的行插入到settings.py中该部分之前MIDDLEWARE,并将嵌入标记中的文件路径写入路径为
{{student.file.get.photo_jpg.url}}
Run Code Online (Sandbox Code Playgroud)
然后在 Chrome 或您正在使用的任何浏览器中进行硬重置。
它对我有用,我希望它也对你有用。
| 归档时间: |
|
| 查看次数: |
2140 次 |
| 最近记录: |