使用AJAX Django从视图获取数据

我不知道如何解决这个问题,情况是这样的:

我有一个名为detail.html的html文件,其中包含以下代码:

{% for choice in question.choice_set.all %}
        <div class="input-group-text">
            <input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}" />
            <label for="choice{{ forloop.counter }}">   {{ choice.choice_text }}</label>
        </div>
    {% endfor %}
    <br />
    <button type="submit" class="btn btn-light mb-2">Vote</button>

I want to send this form with "Vote" button and print another html called results.html with AJAX. I can't do {% extends "results.html" %} because the results.html also has a layout.html extension and must-have info form its view.py function.

{% extends "app/layout.html" %}
{% block content %}

<h2>{{ title }}.</h2>
<h3>{{ message }}</h3>

<h1>{{ question.question_text }}</h1>

{% if not request.user.is_authenticated %}   
    {% if choice.correct %}
        <h3 style="color: green">¡ Respuesta Correcta !</h3>
    {% else %}
        <h3 style="color: red">¡ Respuesta Incorrecta !</h3>
    {% endif %}
{% endif %}

    <table class="table">
        <thead>
            <th scope="col">Choice text</th>
            <th scope="col">Votes</th>
        </thead>
        <tbody>
        {% for choice in question.choice_set.all %}
        <tr>
            <td>{{ choice.choice_text }}</td>
            <td>{{ choice.votes }}</td>
        </tr> 
        {% endfor %}
        </tbody>
    </table>



<a href="{% url 'chart' question.id %}"> Ver grafica</a><br />
<a href="{% url 'index' %}">Contestar otra pregunta?</a>

{% endblock %}

views.py

def results(request, question_id):
    question = get_object_or_404(Question, pk=question_id)
    return render(request, 'polls/results.html', {'title':'Resultados de la pregunta:','question': question})

例如,在PHP中,您可以调用php文件并附加数据结果,此处为示例:

$.ajax({
        url: '../php/ShowXmlQuestions.php',
        success:function(data){
           $('#div').append(data);
        },
    });