0

I have a HTML file that store in different folder with django.

Below is my HTML code that I run under Python Django:

<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>

The output for graph is

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

So the iframe create is 3 for this case, I able saw there is 3 box of the iframe generated but fail to see the content. Anyone can share ideas?

Shi Jie Tio
  • 2,479
  • 5
  • 24
  • 41

2 Answers2

2

The problem may be that the html files you're trying to serve do not have a url. You could do either of these two options:

Option 1: Add a url for each html file in your urls.py. Something like:

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

Option 2: You could serve them as static files. There is some discussion about that in this thread. This would be better suited if you don't know the names of your html files beforehand.

damores
  • 2,251
  • 2
  • 18
  • 31
  • Hi I have try both but the contain still not able show out, any ideas on this? – Shi Jie Tio Mar 25 '19 at 08:12
  • Hi let say array name graph=['A.html','B.html'] then {% for i in graph %} {% endfor %} Any ideas to edit the src links, when i run it return A server error occurred. Please contact the administrator – Shi Jie Tio Mar 25 '19 at 08:55
-1

iframe is not supported in HTML5. U should use embed instead of iframe, but if u want to use iframe then maybe u should use a lower version of html. check this: https://www.w3schools.com/tags/tag_iframe.asp