我想做的是在模板中呈现一个html“ a”文件。并使用jquery .load()将其他html文件嵌入此a.html中。但是我的以下代码失败了。
以下是我的a.html内容:
<html>
<head>
{% load staticfiles %}
<script type="text/javascript" src="{% static "js/jquery-1.10.2.js" %}" />
<script>
$(function(){
$("#includeContent").load("abc.html");
});
</script>
</head>
<body>
<div id="includeContent"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
以下是我的abc.html:
<html>
<body>
<!-- Hello -->
<p>Hello world </p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
以下是我的应用程序树:
- App:
views.py
models.py
- static
-js:
jquery-1.10.2.js
- template:
a.html
abc.html
Run Code Online (Sandbox Code Playgroud)
在Firebug调试器中,我可以看到jquery-1.10.2.js的源代码,因此我认为jquery脚本已成功包含在内。
我要嵌入到a.html中的abc.html应该显示“ Hello world”,但是加载a.html之后我什么都看不到。
有没有办法解决这个问题?
添加“模板”的设置:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
Run Code Online (Sandbox Code Playgroud)
]