The thing I want to do is to render a html "a" file in template. And use jquery .load() to embedded other html files in this a.html. But I failed with my following code.
The following is my a.html content:
<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>
The following is my abc.html:
<html>
<body>
<!-- Hello -->
<p>Hello world </p>
</body>
</html>
The following is my app tree:
- App:
views.py
models.py
- static
-js:
jquery-1.10.2.js
- template:
a.html
abc.html
In Firebug debugger, I can see the source code of jquery-1.10.2.js so I think the jquery script is successfully included.
The abc.html I want to embedded into a.html should show "Hello world" But I cannot see anything after I load the a.html.
Is there a way to fix this?
Add the setting of "Templates":
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',
],
},
},
]