<iframe id="iframe" name="ifra"></iframe>
<form id="fm" action="{% url 'main5' %}" method="POST" target="ifra">
    {% csrf_token %}
    <input name="name"/>
    <input name="age"/>
    <a class="btn btn-success btn-sm" onclick="AjaxSubmit5()">提交</a>
</form>

以上是html代码直接复制到html的body体内

<script>
    function AjaxSubmit5() {
        document.getElementById('iframe').onload = reloadIframe;
        document.getElementById('fm').submit();
    }
    function reloadIframe() {
        console.log(ths.contentWindow);
        var content = this.contentWindow.document.body.innerHTML;
        var obj = JSON.parse(content);
        if (obj.status) {
            alert(obj.message);
        }
    }
</script>

以上是JS代码,可以放在body尾部,或者单独放在一个JS文件

def index5(request):
    return render(request, 'index5.html')
def main5(request):
    import time
    print(request.GET)
    print(request.POST)
    print(request.FILES)
    # print(request.body)
    ret = {'status':True, 'message': '....'}
    import json
    return HttpResponse(json.dumps(ret))

以上是VIEW函数