【发布时间】:2015-09-19 19:43:58
【问题描述】:
我想做的是在模板中呈现一个 html“a”文件。并使用 jquery .load() 在这个 a.html 中嵌入其他 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>
以下是我的abc.html:
<html>
<body>
<!-- Hello -->
<p>Hello world </p>
</body>
</html>
以下是我的应用树:
- App:
views.py
models.py
- static
-js:
jquery-1.10.2.js
- template:
a.html
abc.html
在 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',
],
},
},
]
【问题讨论】:
标签: jquery python html django django-templates