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?

1
  • can you post what is getting rendered in src of iframe do view-source of output page Commented Mar 22, 2019 at 6:53

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi I have try both but the contain still not able show out, any ideas on this?
Hi let say array name graph=['A.html','B.html'] then {% for i in graph %} <iframe width="47%" height="700" src="{% static '{{i|safe}}' %}" ></iframe> {% endfor %} Any ideas to edit the src links, when i run it return A server error occurred. Please contact the administrator
-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

2 Comments

I have try the example in the link, and have a try, but it refuse to connect if i using django package, but if i used stand alone HTML it work well
iframe is recommended for HTML files

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.