[英]How to include html template into another html with javascript
I have an html
page called main.html
that is extended with base.html
.我有一个名为
main.html
的html
页面,该页面使用base.html
扩展。 I like to find a solution how can I include another html
template ( individual_sum.html
) into it with the javascript too.我想找到一个解决方案,如何将另一个
html
模板( individual_sum.html
)与 javascript 一起包含在其中。 individual_sum.html
has lots of javascript codes in the file. individual_sum.html
文件中有很多 javascript 代码。 I don't use external javascript file because I don't know how if there any way to use Django Template Language in js.我不使用外部 javascript 文件,因为我不知道如何在 js 中使用 Django 模板语言。 I have queries in my view that pushes data dynamically so I need DTL.
我的视图中有动态推送数据的查询,因此我需要 DTL。
I included the individual_sum.html
into the main.html
and the content appears but charts and other javascript stuff are blank.我将
individual_sum.html
包含到main.html
中,内容出现,但图表和其他 javascript 内容为空白。
main.html main.html
{% extends 'stressz/base.html' %}
{% block body%}
content of main.html
{% include 'stressz/individual_sum.html' %}
{% endblock %}
Is there any solution to have fully (with javascript) working individual_sum.html
in main.html
?是否有任何解决方案可以在
main.html
中完全(使用 javascript)工作individual_sum.html
? Or can I use external javascript file that has Django's for
and if/elif
statements working in it?或者我可以使用包含 Django 的
for
和if/elif
语句的外部 javascript 文件吗? My aim is to have smaller separated files and not one giant.我的目标是拥有更小的分离文件,而不是一个巨大的。
Yes you can use the javascript externally with Django.是的,您可以在外部使用 javascript 和 Django。 You can create a separate file say
myscript.js
and then add it as a static file to your django project.您可以创建一个单独的文件,例如
myscript.js
,然后将其作为 static 文件添加到您的 django 项目中。 Then link it in the base file of your templates like <script src="{% static 'myscript.js' %}"></script>
.然后将其链接到模板的基本文件中,例如
<script src="{% static 'myscript.js' %}"></script>
。 It will work with every html file that extends from the base file.它适用于从基本文件扩展的每个 html 文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.