你不能这样。更好的方法是通过ajax加载html的那部分。
您的ajax视图:
def update_items(request): product_list = your_data return render(request, 'table_body.html', {'product_list':product_list})您的主要html:
<tbody > {% include 'table_body.html' %}</tbody>table_body.html:
{% for item in product_list %} <tr> <td colspan="2">{{ item.date }}</td> <td id="item_name_format" colspan="6">{{ item.name }}</td> {% if item.category_id %} <td id="item_name_format" colspan="2">{{ item.category_id.level1_desc }}</td> {% endif %} <td id="item_amt_format" colspan="2">${{ item.amount|intcomma }}</td> </tr>{% endfor %}您的ajax看起来像这样:
function update_item(item_num) { console.log(item_num) // sanity check $('.table_body').html('').load( "{% url 'update_items' %}?item_num=" + item_num ); // <--- this pre instead of $.ajax(lala)你在这里使用这个load()



