我正在从Django中单击按钮的Ajax请求中加载 new_question_element.html 。我应该如何在已加载的HTML中使用{%load static%}函数。
我尝试在 new_question_element.html 中传递{%load static%}标签,并尝试调用{%static“ image path”%},但它没有处理这些标签。从Django URL调用可以正常工作,但是从Java脚本外部文件(已加载到我的 index.html
中)的Ajax请求调用中却无法正常工作index.html
<!DOCTYPE html>
<html lang="en">
{% load static %}
<head>
...
...
<script src="{% static 'letssurvey/test/vendor/script.js' %}"></script>
</body>
</html>
script.js
$(document).on('click','.j_add-new-question-btn',function(){
$.ajax({
type: "GET",
url: "Path to new_question_element.html",
success: function(data)
{
new_question_area.html(data);
new_question_area.find(".j_new-question-number").text(g_question_number);
add_btn.fadeOut();
}
});
});
new_question_element.html
{% load static %}
....
....
<button class="col-xs-12 bg-subtle text-color question-type--button text-center qtype-item waves-init-wrapper j_select-element-type select-type" id="ele_single_choice_id" data-name="Single Choice">
<div class="pointer d-flex align-items-center justify-content-between">
<div class="lv-title d-flex align-items-center">
<div class="question-type--icon vertical-align">
<img src="{% static 'data/image/mcq_single.svg' %}" alt="Single Choice" class="qtype-icon">
<i class="fa fa-spinner fa-spin"></i>
</div>
<div class="question-type--title--wrapper">
<span title="" class="question-type--title">
<span class="m-b-0">Single Choice</span>
<span class="text-muted text-sm">
</span>
</span>
</div>
</div>
</div>
</button>
该模板正在渲染,并且一切正常,但是img标签的src属性未显示图像。我要显示图像