URLS--->

    re_path('main3/', views.main3, name='main3'),
    re_path('index3/', views.index3, name='index3'),

 

VIEW--->

def index3(request):
    return render(request, 'index3.html')


def main3(request):
    print(request.POST.get('name'))
    print(request.POST.get('age'))
    print(request.POST.get('gender'))
    print(request.POST)
    return HttpResponse("it's Ok")

 

HTML--->

<div class="container">
    <div class="row">
        <h1>2.Ajax发送POST请求</h1>
        <div>
            <a class="btn btn-primary" style="display: inline-block" onclick="AjaxPost1();">AjaxGet</a>
        </div>
        {% csrf_token %}

--------------------------------下面是JS代码------------------------------------
</div>
<script src="/static/jquery-3.1.1.js"></script> <script> function AjaxPost1() { $.ajax({ url: '{% url 'main3' %}', type: 'POST', data: { 'name': 'apollo', 'age':28, 'gender':'male', 'csrfmiddlewaretoken':$('input[name="csrfmiddlewaretoken"]').val() }, success: function (arg) { } }) } </script> </div>

 

RESULT--->