【问题标题】:How to load iframe in Python Django?如何在 Python Django 中加载 iframe?
【发布时间】:2019-08-13 02:53:22
【问题描述】:

我有一个与 django 存储在不同文件夹中的 HTML 文件。

下面是我在 Python Django 下运行的 HTML 代码:

<body>
{% load staticfiles %}
{{graph|safe}}
{% for i in graph %}
<div class="box">
<iframe width="47%" height="700" src="{{i|safe}}"  frameborder="1" allow="autoplay; encrypted-media" allowfullscreen align="left" ></iframe>
</div>
{% endfor %}
</body>

图形的输出是

["a.html","e.html","I.html"]

因此,对于这种情况,iframe create 是 3,我可以看到生成了 3 个 iframe 框,但看不到内容。任何人都可以分享想法吗?

【问题讨论】:

  • 你能把在srciframe 中呈现的内容发布到输出页面的视图源

标签: python html django python-3.x iframe


【解决方案1】:

问题可能是您尝试提供的 html 文件没有 url。您可以执行以下两个选项之一:

选项 1: 为您的 urls.py 中的每个 html 文件添加一个 url。比如:

urlpatterns = [
    path('a.html', TemplateView.as_view(template_name="a.html")),
]

选项 2:您可以将他们作为 static files 提供服务。 this thread 对此进行了一些讨论。如果您事先不知道 html 文件的名称,这将更适合。

【讨论】:

  • 您好,我都尝试了,但包含仍然无法显示,对此有什么想法吗?
  • 嗨,让我们说数组名称 graph=['A.html','B.html'] 然后 {% for i in graph %} {% endfor %} 编辑 src 链接的任何想法,当我运行它时返回发生服务器错误。请联系管理员
【解决方案2】:

HTML5 不支持 iframe。你应该使用 embed 而不是 iframe,但如果你想使用 iframe,那么也许你应该使用较低版本的 html。检查这个:https://www.w3schools.com/tags/tag_iframe.asp

【讨论】:

  • 我已经尝试了链接中的示例,并试了一下,但是如果我使用 django 包它会拒绝连接,但如果我使用独立的 HTML 它工作得很好
猜你喜欢
  • 2012-10-07
  • 1970-01-01
  • 2017-07-05
  • 1970-01-01
  • 2014-02-14
  • 2018-01-16
  • 1970-01-01
  • 2015-03-31
  • 1970-01-01
相关资源
最近更新 更多