django中ajax的提交方式为POST,返回到后端是GET

求大神指教

html:

{% for student in all %}
<tr>
                            <th scope="col" id="{{ student.username }}">{{ student.username }}</th>
                            <th scope="col">{{ student.name }}</th>
                            <th scope="col">{{ student.gender }}</th>
                            <th scope="col">{{ student.phone }}</th>
                            <th scope="col">{{ student.addr }}</th>
                            <th scope="col">
                                <button type="submit" class="btn btn-secondary">编辑信息</button>
                                <button type="submit" class="btn btn-info" data-toggle="modal" data-target="#update_password">修改密码</button>
                                <button type="submit" class="btn btn-danger del_account">删除账号</button>
                                <div class="modal fade" id="update_password" aria-labelledby="exampleModalLabel" aria-hidden="true">
                                    <div class="modal-dialog">
                                        <div class="modal-content">
                                            <div class="modal-header">
                                                <h5 class="text-danger">修改密码</h5>
                                            </div>
                                            <div class="modal-body">
                                                <div class="form-group">
                                                    <lable for="recipient-name" class="col-form-label">请输入修改后的密码:&nbsp;&nbsp;&nbsp;</lable>
                                                    <input type="password" class="form-control">
                                                </div>
                                                <div class="form-group">
                                                    <lable for="recipient-name" class="col-form-label">请确认修改后的密码:&nbsp;&nbsp;&nbsp;</lable>
                                                    <input type="password" class="form-control">
                                                </div>
                                            </div>
                                            <div class="modal-footer">
                                                <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                                                <button type="submit" class="btn btn-primary update_password">确认修改</button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </th>
                        </tr>

js:

$(document).ready(function () {
    $(".del_account").click(function () {
        if (confirm("是否删除?")){
            var username = $(this).parent("th").parent("tr").children(":first").attr('id');
            $.ajax({
                url:"/system/del_account",
                type:"POST",
                data:{'csrfmiddlewaretoken': $('[name="csrfmiddlewaretoken"]').val(),"username":username},
                success:function (data) {
                    alert(username)
                }
            })
        }
    })
})

views:

 

那你发送请求看看具体是什么请求,浏览器f12审查元素。network里看看,先确定是前端还是后端问题,如果network是post的话,大概率是后端代码有问题

找到问题了!

因为我后端的url是这样子的

他带有“/”符号

而我的ajax里的url则是

他没有携带“/”符号,所以url没有匹配到,如果有跨站请求,匹配到后之后还应该给数据添加上