11-Django项目--Ajax请求二

目录

模版:

demo_list.html

perform_list.html

数据库操作: 

路由:

视图函数:

Ajax_data.py

perform.py


模版:

demo_list.html

{% extends "index/index.html" %}
{% load static %}
# 未实现修改,删除操作

{% block content %}
    <div class="container">
        <h1>Ajax演示-one</h1>
        <input type="button" id="button-one" class="btn btn-success" value="点我">
        <hr>
        <table border="1">
            <thead>
            <th>一级分类</th>
            <th>二级分类</th>
            <th>名称</th>
            </thead>
            <tbody id="tBody" align="center"></tbody>
        </table>

        <h1>Ajax演示-two</h1>
        <input type="text" id="username" placeholder="请输入账号">
        <input type="text" id="password" placeholder="请输入账号">
        <input type="button" id="button-two" class="btn btn-success" value="点我">
        <hr>
        <h1>Ajax演示-three</h1>
        <form id="form-three">
            <input type="text" id="name" placeholder="姓名">
            <input type="text" id="age" placeholder="年龄">
            <input type="text" id="love" placeholder="爱好">
        </form>
        <input type="button" id="button-three" class="btn btn-success" value="点我">

        <hr>
    </div>
    <hr>
    {# 添加数据 #}
    <div class="container">
        <div class="panel panel-warning">
            <div class="panel-heading">
                <h3 class="panel-title">任务列表</h3>
            </div>
            <div class="panel-body clearfix">
                <form id="formAdd">
                    {% for field in form %}
                        <div class="col-xs-6">
                            <label for="">{{ field.label }}</label>
                            {{ field }}
                            <span id="con-msg" style="color: red; position: absolute;margin-left: 80px">{{ field.errors }}</span>
                        </div>
                    {% endfor %}
                <div class="col-xs-12">
                    <button type="button" id="btnAdd" class="btn btn-success">提交</button>
                </div>
                </form>
            </div>
        </div>
    </div>
    {#展示数据#}
    <div class="container">
        <div class="panel panel-danger">
            <div class="panel-heading">
                <h3 class="panel-title">任务展示</h3>
            </div>
            <div class="panel-body">
                <table class="table table-bordered">
                    <thead>
                    <tr>
                        <th>任务ID</th>
                        <th>任务标题</th>
                        <th>任务级别</th>
                        <th>任务内容</th>
                        <th>负责人</th>
                        <th>开始时间</th>
                        <th>任务状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {% for data in queryset %}
                        <tr>
                        <th>{{ data.id }}</th>
                        <th>{{ data.title }}</th>
                        <th>{{ data.get_level_display }}</th>
                        <th>{{ data.detail }}</th>
                        <th>{{ data.user.name }}</th>
                        <th>{{ data.times }}</th>
                        <th>{{ data.get_code_display }}</th>
                        <th>
                            <a href="#">删除</a>
                            <a href="#">修改</a>
                        </th>

                    </tr>
                    {% endfor %}

                    </tbody>
                </table>
            </div>
        </div>
    </div>
{% endblock %}

{% block js %}
    <script>
        // 函数调用
        $(function () {
            bindBtnOne();
            bindBtnTwo();
            bindBtnThree();
            bindBtnEvent();
        })

        function bindBtnOne() {
            // 通过id属性,找见某个标签,之后再点击的时候,触发一个函数
            $("#button-one").click(function () {
                //在点击这个按钮的时候,进行一次数据提交
                $.ajax({
                    // 请求地址
                    url: "/demo/one/",
                    // 请求类型
                    type: "post",
                    // 表单数据
                    data: {
                        type: "text",
                        love: "lanqiu"
                    },
                    // 如果请求成功,则接受后端传输过来的数据
                    success: function (res) {
                        var list = res.list;
                        var htmlStr = "";
                        for (var i = 0; i < list.length; i++) {
                            var emp = list[i]
                            /*
                            <tr>
                                <td>水果</td>
                                <td>水果</td>
                                <td>水果</td>
                            </tr>
                             */
                            htmlStr += "<tr>";
                            htmlStr += "<td>" + emp.prodCat + "</td>"
                            htmlStr += "<td>" + emp.prodPcat + "</td>"
                            htmlStr += "<td>" + emp.prodName + "</td>"
                            htmlStr += "</tr>";
                            // 通过id定位到一个标签,将html内容添加进去
                            document.getElementById("tBody").innerHTML = htmlStr;
                        }
                    }
                })

            })
        }

        function bindBtnTwo() {
            // 通过id属性,找见某个标签,之后再点击的时候,触发一个函数
            $("#button-two").click(function () {
                //在点击这个按钮的时候,进行一次数据提交
                $.ajax({
                    // 请求地址
                    url: "/demo/two/",
                    // 请求类型
                    type: "post",
                    // 表单数据
                    data: {
                        username: $("#username").val(),
                        password: $("#password").val()
                    },
                    // 如果请求成功,则接受后端传输过来的数据
                    success: function (res) {
                        alert(res)
                    }
                })

            })
        }

        function bindBtnThree() {
            // 通过id属性,找见某个标签,之后再点击的时候,触发一个函数
            $("#button-three").click(function () {
                //在点击这个按钮的时候,进行一次数据提交
                $.ajax({
                    // 请求地址
                    url: "/demo/two/",
                    // 请求类型
                    type: "post",
                    // 表单数据
                    data: $("#form-three").serialize(),
                    // 如果请求成功,则接受后端传输过来的数据
                    success: function (res) {
                        console.log(res)
                    }
                })

            })
        }

        function bindBtnEvent() {
            // 通过id属性,找见某个标签,之后再点击的时候,触发一个函数
            $("#btnAdd").click(function () {
                // 清空错误信息
                $("#con-msg").empty();
                //在点击这个按钮的时候,进行一次数据提交
                $.ajax({
                    // 请求地址
                    url: "/demo/add/",
                    // 请求类型
                    type: "post",
                    // 表单数据
                    data: $("#formAdd").serialize(),
                    // 如果请求成功,则接受后端传输过来的数据
                    datatype:"JSON",
                    success: function (res) {
                        if(res.status){
                            alert("添加成功");
                            // 刷新页面
                            location.reload();
                        }else {
                            {#console.log(res.error);#}
                            // each 遍历字典error,将键和值给到函数
                            // 将所有的异常,分配带每个框 name是error当中的键,data是error当中的值
                            $.each(res.error, function (name, data) {
                                // 通过id值,找到输入框,将错误信息展示在输入框的附近
                                $("#id_"+name).next().text(data[0])
                            })
                        }

                    }
                })

            })
        }

    </script>
{% endblock %}

perform_list.html

 未做修改.

{% extends "index/index.html" %}


{% block content %}
    <div class="container">
        <!-- Button trigger modal -->
        <button type="button" class="btn btn-success btn-lg" id="btnAdd">
            新生入学
        </button>

        <!-- Modal -->
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" >
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel">添加信息</h4>
                    </div>
                    <div class="modal-body">
                        <form id="formAdd">
                            <div class="clearfix">
                                {% for field in form %}
                                    <div class="col-xs-6">
                                        <label for="">{{ field.label }}</label>
                                        {{ field }}
                                        <span id="con-msg"
                                              style="color: red; position: absolute;margin-left: 80px">{{ field.errors }}</span>
                                    </div>
                                {% endfor %}
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-warning" data-dismiss="modal">Close</button>
                        <button type="button" class="btn btn-success" id="btnSave">Save</button>
                    </div>
                </div>
            </div>
        </div>
    </div>

    {# 内容展示 #}
    <div class="container" style="margin-top: 10px">
        <div class="panel panel-success">
            <div class="panel-heading">
                <h3 class="panel-title">新生列表</h3>
            </div>
            <div class="panel-body">
                <table class="table table-bordered">
                    <thead>
                    <tr>
                        <th>ID</th>
                        <th>订单号</th>
                        <th>来源</th>
                        <th>姓名</th>
                        <th>日期</th>
                        <th>学费</th>
                        <th>销售</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {% for data in queryset %}
                        <tr class="success">
                            <th>{{ data.id }}</th>
                            <th>{{ data.oid }}</th>
                            <th>{{ data.source }}</th>
                            <th>{{ data.title }}</th>
                            <th>{{ data.times }}</th>
                            <th>{{ data.price }}</th>
                            <th>{{ data.name }}</th>
                            <th>
                                <button uid="{{ data.id }}" style="border: none" class="btn btn-danger btn-xs btn-delete">删除
                                </button>
                                <button style="border: none" class="btn btn-info btn-xs">修改</button>
                            </th>

                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>

    </div>

    {# 删除警告框 #}
    <div class="modal fade" id="btnDelete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="alert alert-danger alert-dismissible fade in" role="alert" style="width: 500px">
                <h4>你要确认删除吗</h4>
                <p>你要是删了,业绩可就没了</p>
                <p>
                    <button type="button" class="btn btn-success" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-warning" id="contentDelete">删除</button>
                </p>
            </div>
        </div>
    </div>

{% endblock %}

{% block js %}
    <script>
    var DELETE_ID = undefined;
        $(function () {
            bindBtnAdd();
            bindBtnSave();
            bindBtnDelete();
            bindBtnDeleteContent();
        })

        function bindBtnAdd() {
            $("#btnAdd").click(function () {
                $("#myModal").modal("show")
            })
        }

        function bindBtnSave() {
            $("#btnAdd").click(function () {
                $("#btnSave").click(function () {
                    $.ajax({
                        url: "/parform/add/",
                        type: "post",
                        data: $("#formAdd").serialize(),
                        dataType: "JSON",
                        success: function (res) {
                            if (res.status) {
                                // 关闭窗口
                                $("#myModal").modal("hide");
                                location.reload();
                            } else {
                                $.each(res.error, function (name, data) {
                                    $("#id_" + name).next().text(data[0])
                                })
                            }
                        }
                    })
                })
            })
        }

        function bindBtnDelete() {
            $(".btn-delete").click(function () {
                $("#btnDelete").modal("show");
                {#console.log($(this).attr("uid"))#}
                DELETE_ID = $(this).attr("uid")
            })
        }

        function bindBtnDeleteContent() {
            $("#contentDelete").click(function () {
                $.ajax({
                    url:"/parform/delete/",
                    type:"get",
                    dataType: "JSON",
                    data:{uid:DELETE_ID},
                    success:function (res) {
                        if (res.status){
                             $("#btnDelete").modal("hide");
                             //删除对应的tr标签
                             {#$("tr[uid='" + DELETE_ID + "']").remove(),#}
                             location.reload()
                        }
                    }

                })
            })
        }
    </script>
{% endblock %}


数据库操作: 


路由:

 


视图函数:

Ajax_data.py

# -*- coding:utf-8 -*-
from django.shortcuts import render, redirect, HttpResponse
from django.views.decorators.csrf import csrf_exempt
from demo_one import models
from django.http import JsonResponse
from django import forms
import json


class DemoModelFoem(forms.ModelForm):
    class Meta:
        model = models.Demp
        fields = "__all__"
        widgets = {
            "detail":forms.TextInput
        }

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        for name, field in self.fields.items():
            field.widget.attrs = {"class": "form-control", "autocomplete": "off"}


@csrf_exempt
def demo_list(request):
    queryset = models.Demp.objects.all()
    form = DemoModelFoem()
    content = {
        "form": form,
        "queryset": queryset
    }
    return render(request, "Ajax-demo/demo_list.html",content)


@csrf_exempt
def demo_add(request):
    form = DemoModelFoem(request.POST)
    if form.is_valid():
        form.save()
        dict_data = {"status": True}
        return JsonResponse(dict_data)
    dict_data = {"error": form.errors}
    return JsonResponse(dict_data)


@csrf_exempt
def demo_one(request):
    dict_data = {
        "current": 1,
        "limit": 20,
        "count": 82215,
        "list": [
            {
                "id": 1623704,
                "prodName": "菠萝",
                "prodCatid": 1187,
                "prodCat": "水果",
                "prodPcatid": 1211,
                "prodPcat": "其他类",
                "lowPrice": "2.0",
                "highPrice": "3.0",
                "avgPrice": "2.5",
                "place": "",
                "specInfo": "箱装(上六下六)",
                "unitInfo": "斤",
                "pubDate": "2024-06-04 00:00:00",
                "status": "null",
                "userIdCreate": 138,
                "userIdModified": "null",
                "userCreate": "admin",
                "userModified": "null",
                "gmtCreate": "null",
                "gmtModified": "null"
            },
            {
                "id": 1623703,
                "prodName": "凤梨",
                "prodCatid": 1187,
                "prodCat": "水果",
                "prodPcatid": 1211,
                "prodPcat": "其他类",
                "lowPrice": "3.5",
                "highPrice": "5.5",
                "avgPrice": "4.5",
                "place": "国产",
                "specInfo": "",
                "unitInfo": "斤",
                "pubDate": "2024-06-04 00:00:00",
                "status": "null",
                "userIdCreate": 138,
                "userIdModified": "null",
                "userCreate": "admin",
                "userModified": "null",
                "gmtCreate": "null",
                "gmtModified": "null"
            },
            {
                "id": 1623702,
                "prodName": "圣女果",
                "prodCatid": 1187,
                "prodCat": "水果",
                "prodPcatid": 1211,
                "prodPcat": "其他类",
                "lowPrice": "4.0",
                "highPrice": "5.0",
                "avgPrice": "4.5",
                "place": "",
                "specInfo": "千禧",
                "unitInfo": "斤",
                "pubDate": "2024-06-04 00:00:00",
                "status": "null",
                "userIdCreate": 138,
                "userIdModified": "null",
                "userCreate": "admin",
                "userModified": "null",
                "gmtCreate": "null",
                "gmtModified": "null"
            },
            {
                "id": 1623701,
                "prodName": "百香果",
                "prodCatid": 1187,
                "prodCat": "水果",
                "prodPcatid": 1211,
                "prodPcat": "其他类",
                "lowPrice": "8.0",
                "highPrice": "10.0",
                "avgPrice": "9.0",
                "place": "",
                "specInfo": "",
                "unitInfo": "斤",
                "pubDate": "2024-06-04 00:00:00",
                "status": "null",
                "userIdCreate": 138,
                "userIdModified": "null",
                "userCreate": "admin",
                "userModified": "null",
                "gmtCreate": "null",
                "gmtModified": "null"
            },
            {
                "id": 1623700,
                "prodName": "九九草莓",
                "prodCatid": 1187,
                "prodCat": "水果",
                "prodPcatid": 1211,
                "prodPcat": "其他类",
                "lowPrice": "6.0",
                "highPrice": "12.0",
                "avgPrice": "9.0",
                "place": "",
                "specInfo": "",
                "unitInfo": "斤",
                "pubDate": "2024-06-04 00:00:00",
                "status": "null",
                "userIdCreate": 138,
                "userIdModified": "null",
                "userCreate": "admin",
                "userModified": "null",
                "gmtCreate": "null",
                "gmtModified": "null"
            },
            {
                "id": 1623699,
                "prodName": "杨梅",
                "prodCatid": 1187,
                "prodCat": "水果",
                "prodPcatid": 1211,
                "prodPcat": "其他类",
                "lowPrice": "8.0",
                "highPrice": "19.0",
                "avgPrice": "13.5",
                "place": "",
                "specInfo": "",
                "unitInfo": "斤",
                "pubDate": "2024-06-04 00:00:00",
                "status": "null",
                "userIdCreate": 138,
                "userIdModified": "null",
                "userCreate": "admin",
                "userModified": "null",
                "gmtCreate": "null",
                "gmtModified": "null"
            },
            {
                "id": 1623698,
                "prodName": "蓝莓",
                "prodCatid": 1187,
                "prodCat": "水果",
                "prodPcatid": 1211,
                "prodPcat": "其他类",
                "lowPrice": "25.0",
                "highPrice": "45.0",
                "avgPrice": "35.0",
                "place": "",
                "specInfo": "",
                "unitInfo": "斤",
                "pubDate": "2024-06-04 00:00:00",
                "status": "null",
                "userIdCreate": 138,
                "userIdModified": "null",
                "userCreate": "admin",
                "userModified": "null",
                "gmtCreate": "null",
                "gmtModified": "null"
            },
            {
                "id": 1623697,
                "prodName": "火龙果",
                "prodCatid": 1187,
                "prodCat": "水果",
                "prodPcatid": 1211,
                "prodPcat": "其他类",
                "lowPrice": "7.0",
                "highPrice": "11.0",
                "avgPrice": "9.0",
                "place": "",
                "specInfo": "红",
                "unitInfo": "斤",
                "pubDate": "2024-06-04 00:00:00",
                "status": "null",
                "userIdCreate": 138,
                "userIdModified": "null",
                "userCreate": "admin",
                "userModified": "null",
                "gmtCreate": "null",
                "gmtModified": "null"
            },
            {
                "id": 1623696,
                "prodName": "火龙果",
                "prodCatid": 1187,
                "prodCat": "水果",
                "prodPcatid": 1211,
                "prodPcat": "其他类",
                "lowPrice": "5.3",
                "highPrice": "7.3",
                "avgPrice": "6.3",
                "place": "",
                "specInfo": "白",
                "unitInfo": "斤",
                "pubDate": "2024-06-04 00:00:00",
                "status": "null",
                "userIdCreate": 138,
                "userIdModified": "null",
                "userCreate": "admin",
                "userModified": "null",
                "gmtCreate": "null",
                "gmtModified": "null"
            },
            {
                "id": 1623695,
                "prodName": "木瓜",
                "prodCatid": 1187,
                "prodCat": "水果",
                "prodPcatid": 1211,
                "prodPcat": "其他类",
                "lowPrice": "4.5",
                "highPrice": "5.0",
                "avgPrice": "4.75",
                "place": "",
                "specInfo": "",
                "unitInfo": "斤",
                "pubDate": "2024-06-04 00:00:00",
                "status": "null",
                "userIdCreate": 138,
                "userIdModified": "null",
                "userCreate": "admin",
                "userModified": "null",
                "gmtCreate": "null",
                "gmtModified": "null"
            },
            {
                "id": 1623694,
                "prodName": "桑葚",
                "prodCatid": 1187,
                "prodCat": "水果",
                "prodPcatid": 1211,
                "prodPcat": "其他类",
                "lowPrice": "6.0",
                "highPrice": "9.0",
                "avgPrice": "7.5",
                "place": "",
                "specInfo": "",
                "unitInfo": "斤",
                "pubDate": "2024-06-04 00:00:00",
                "status": "null",
                "userIdCreate": 138,
                "userIdModified": "null",
                "userCreate": "admin",
                "userModified": "null",
                "gmtCreate": "null",
                "gmtModified": "null"
            },
            {
                "id": 1623693,
                "prodName": "柠檬",
                "prodCatid": 1187,
                "prodCat": "水果",
                "prodPcatid": 1211,
                "prodPcat": "其他类",
                "lowPrice": "3.0",
                "highPrice": "4.0",
                "avgPrice": "3.5",
                "place": "",
                "specInfo": "",
                "unitInfo": "斤",
                "pubDate": "2024-06-04 00:00:00",
                "status": "null",
                "userIdCreate": 138,
                "userIdModified": "null",
                "userCreate": "admin",
                "userModified": "null",
                "gmtCreate": "null",
                "gmtModified": "null"
            },
            {
                "id": 1623692,
                "prodName": "姑娘果(灯笼果)",
                "prodCatid": 1187,
                "prodCat": "水果",
                "prodPcatid": 1211,
                "prodPcat": "其他类",
                "lowPrice": "12.5",
                "highPrice": "25.0",
                "avgPrice": "18.75",
                "place": "",
                "specInfo": "",
                "unitInfo": "斤",
                "pubDate": "2024-06-04 00:00:00",
                "status": "null",
                "userIdCreate": 138,
                "userIdModified": "null",
                "userCreate": "admin",
                "userModified": "null",
                "gmtCreate": "null",
                "gmtModified": "null"
            },
            {
                "id": 1623691,
                "prodName": "鸭梨",
                "prodCatid": 1187,
                "prodCat": "水果",
                "prodPcatid": "null",
                "prodPcat": "梨类",
                "lowPrice": "1.8",
                "highPrice": "2.0",
                "avgPrice": "1.9",
                "place": "",
                "specInfo": "",
                "unitInfo": "斤",
                "pubDate": "2024-06-04 00:00:00",
                "status": "null",
                "userIdCreate": 138,
                "userIdModified": "null",
                "userCreate": "admin",
                "userModified": "null",
                "gmtCreate": "null",
                "gmtModified": "null"
            },
            {
                "id": 1623690,
                "prodName": "雪花梨",
                "prodCatid": 1187,
                "prodCat": "水果",
                "prodPcatid": "null",
                "prodPcat": "梨类",
                "lowPrice": "1.6",
                "highPrice": "1.8",
                "avgPrice": "1.7",
                "place": "",
                "specInfo": "",
                "unitInfo": "斤",
                "pubDate": "2024-06-04 00:00:00",
                "status": "null",
                "userIdCreate": 138,
                "userIdModified": "null",
                "userCreate": "admin",
                "userModified": "null",
                "gmtCreate": "null",
                "gmtModified": "null"
            },
            {
                "id": 1623689,
                "prodName": "皇冠梨",
                "prodCatid": 1187,
                "prodCat": "水果",
                "prodPcatid": "null",
                "prodPcat": "梨类",
                "lowPrice": "2.7",
                "highPrice": "2.8",
                "avgPrice": "2.75",
                "place": "",
                "specInfo": "纸箱",
                "unitInfo": "斤",
                "pubDate": "2024-06-04 00:00:00",
                "status": "null",
                "userIdCreate": 138,
                "userIdModified": "null",
                "userCreate": "admin",
                "userModified": "null",
                "gmtCreate": "null",
                "gmtModified": "null"
            },
            {
                "id": 1623688,
                "prodName": "丰水梨",
                "prodCatid": 1187,
                "prodCat": "水果",
                "prodPcatid": "null",
                "prodPcat": "梨类",
                "lowPrice": "2.8",
                "highPrice": "3.1",
                "avgPrice": "2.95",
                "place": "",
                "specInfo": "",
                "unitInfo": "斤",
                "pubDate": "2024-06-04 00:00:00",
                "status": "null",
                "userIdCreate": 138,
                "userIdModified": "null",
                "userCreate": "admin",
                "userModified": "null",
                "gmtCreate": "null",
                "gmtModified": "null"
            },
            {
                "id": 1623687,
                "prodName": "酥梨",
                "prodCatid": 1187,
                "prodCat": "水果",
                "prodPcatid": "null",
                "prodPcat": "梨类",
                "lowPrice": "2.0",
                "highPrice": "2.5",
                "avgPrice": "2.25",
                "place": "",
                "specInfo": "",
                "unitInfo": "斤",
                "pubDate": "2024-06-04 00:00:00",
                "status": "null",
                "userIdCreate": 138,
                "userIdModified": "null",
                "userCreate": "admin",
                "userModified": "null",
                "gmtCreate": "null",
                "gmtModified": "null"
            },
            {
                "id": 1623686,
                "prodName": "库尔勒香梨",
                "prodCatid": 1187,
                "prodCat": "水果",
                "prodPcatid": "null",
                "prodPcat": "梨类",
                "lowPrice": "3.5",
                "highPrice": "5.9",
                "avgPrice": "4.7",
                "place": "",
                "specInfo": "",
                "unitInfo": "斤",
                "pubDate": "2024-06-04 00:00:00",
                "status": "null",
                "userIdCreate": 138,
                "userIdModified": "null",
                "userCreate": "admin",
                "userModified": "null",
                "gmtCreate": "null",
                "gmtModified": "null"
            },
            {
                "id": 1623685,
                "prodName": "红香酥梨",
                "prodCatid": 1187,
                "prodCat": "水果",
                "prodPcatid": "null",
                "prodPcat": "梨类",
                "lowPrice": "2.5",
                "highPrice": "2.6",
                "avgPrice": "2.55",
                "place": "",
                "specInfo": "",
                "unitInfo": "斤",
                "pubDate": "2024-06-04 00:00:00",
                "status": "null",
                "userIdCreate": 138,
                "userIdModified": "null",
                "userCreate": "admin",
                "userModified": "null",
                "gmtCreate": "null",
                "gmtModified": "null"
            }
        ]
    }
    # return HttpResponse(json.dumps(dict_data, ensure_ascii=False))
    return JsonResponse(dict_data)


@csrf_exempt
def demo_two(request):
    print(request.POST)
    dict_data = {
        "start": True
    }
    return JsonResponse(dict_data)

perform.py

# -*- coding:utf-8 -*-
from django.shortcuts import render,redirect,HttpResponse
from django.views.decorators.csrf import csrf_exempt
from django.http import JsonResponse
from demo_one import models
from datetime import datetime
from django import forms


class PerformModelForm(forms.ModelForm):
    class Meta:
        model = models.Perform
        exclude = ["times", "name"]

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        for name, field in self.fields.items():
            field.widget.attrs = {"class": "form-control", "autocomplete": "off"}


def perform_list(request):
    form = PerformModelForm()
    queryset = models.Perform.objects.all()
    return render(request, "Ajax-demo/perform_list.html", {"form": form, "queryset":queryset})


@csrf_exempt
def perform_add(request):
    form = PerformModelForm(data=request.POST)
    if form.is_valid():

        # 自动保存时间和对应的人员
        form.instance.name = request.session["info"]["username"]
        form.instance.times = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        # print(request.session["info"]["username"])
        # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
        form.save()

        return JsonResponse({"status": True})
    return JsonResponse({"status": False, "error": form.errors})


@csrf_exempt
def perform_delete(request):
    uid = request.GET.get("uid")
    exists = models.Perform.objects.filter(id=uid).exists()
    if not exists:
        return JsonResponse({"status": False, "error": "数据已被删除"})
    models.Perform.objects.filter(id=uid).delete()
    return JsonResponse({"status":True})

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/746942.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

基于YOLOv8的多端车流检测系统(用于毕设+开源)

目录 ✨基于YOLOv8&#x1f680;的多端车流检测系统-MTAS (Multi-Platform Traffic Analysis System) 一、基本功能介绍 1、客户端 &#xff08;pyside6yolov8pytorch&#xff09; 2、网页端&#xff08;Vue3TypestriptPython3MySQL&#xff09; 3、创新点&#xff08;毕设需…

2024年最新通信安全员考试题库

61.架设架空光缆&#xff0c;可使用吊板作业的情况是&#xff08;&#xff09;。 A.在2.2/7规格的电杆与墙壁之间的吊线上&#xff0c;吊线高度5m B.在2.2/7规格的墙壁与墙壁之间的吊线上&#xff0c;吊线高度6m C.在2.2/7规格的电杆与电杆之间的吊线上&#xff0c;吊线高度…

【嵌入式 RT-Thread】一种优雅的使用 [互斥锁] 和 [信号量] 解决数据多路并发思路

rt-thread 中的信号量和互斥锁在工业开发项目中的应用&#xff0c;本博文主要介绍了一种优雅的使用 [互斥锁] 和 [信号量] 解决数据多路并发思路 2024-06 by 积跬步、至千里 目录 0. 个人简介 && 授权须知1. 工业场景描述1.1 工业数据采集需求1.2 总线协议与数据采集 2…

杭州代理记账报税全程托管专业实力全面指南

杭州代理记税报税服务可以为企业提供全程托管财务管理解决方案&#xff0c;确保企业的财务工作专业、高效、合规。以下是杭州代理记税报税服务全面指南&#xff1a; https://www.9733.cn/news/detail/185.html 一、代理记账报税服务的内容 基础服务&#xff1a; 每日记&#xf…

昇思25天学习打卡营第3天|张量Tensor

认识张量 张量&#xff0c;是一个数据结构&#xff0c;也可以说是一个函数&#xff0c;它描述了标量、矢量和张量之间线性关系。这些关系包括 内积、外积、线性映射以及笛卡尔积。张量中既有大小、又有方向。张量由多个数值构成&#xff0c;在n维空间里&#xff0c;会出现 n …

java对word文档预设参数填值并生成

目录 &#xff08;1&#xff09;定义word文档模板 &#xff08;2&#xff09;模板二次处理 处理模板图片&#xff0c;不涉及图片可以跳过 处理模板内容 &#xff08;3&#xff09;java对word模板填值 &#xff08;4&#xff09;Notepad的XML Tools插件安装 工作上要搞一个…

Yolo v5实现细节(2)

Yolo v5代码实现细节 IOU系列损失 在之前的yolo v3中我们使用的定位损失主要使用的是差值平方的形式&#xff0c;通过预测边界框的参数和真实边界框的参数来进行计算求解的。 定位损失 L loc ( t , g ) ∑ i ∈ pos ( σ ( t x i ) − g ^ x i ) 2 ( σ ( t y i ) − g ^ …

c语言学习记录(十)———函数

文章目录 前言一、函数的基本用法二、函数的参数传递1.基本方式2 数组在函数中的传参 前言 一个学习C语言的小白~ 有问题评论区或私信指出~ 提示&#xff1a;以下是本篇文章正文内容&#xff0c;下面案例可供参考 一、函数的基本用法 函数是一个完成特定功能的代码模块&…

【Linux】锁|死锁|生产者消费者模型

&#x1f525;博客主页&#xff1a; 我要成为C领域大神&#x1f3a5;系列专栏&#xff1a;【C核心编程】 【计算机网络】 【Linux编程】 【操作系统】 ❤️感谢大家点赞&#x1f44d;收藏⭐评论✍️ 本博客致力于知识分享&#xff0c;与更多的人进行学习交流 ​ ​ 访问互斥 …

modelsim做后仿真的一点思路

这是以TD_5.6.3_Release_88061生成的网表文件&#xff08;其他工具生成的网表文件类似&#xff09;&#xff0c;与modelsim联合进行门级仿真的样例&#xff0c;时序仿真与门级仿真的方法类似&#xff0c;只是增加了标准延时文件。 1、建立门级仿真工程 将门级网表和testbench添…

深度学习31-33

1.负采样方案 &#xff08;1&#xff09;为0是负样本&#xff0c;负样本是认为构造出来的。正样本是有上下文关系 负采样的target是1&#xff0c;说明output word 在input word之后。 2.简介与安装 &#xff08;1&#xff09;caffe:比较经常用于图像识别&#xff0c;有卷积网…

一文详细了解Bootloader

Bootloader是什么 bootloader是一个引导加载程序&#xff0c;它的主要作用是初始化硬件设备、设置硬件参数&#xff0c;并加载操作系统内核。在嵌入式系统中&#xff0c;bootloader是硬件启动后第一个被执行的程序&#xff0c;它位于操作系统和硬件之间&#xff0c;起到桥梁的…

操作符详解(上) (C语言)

操作符详解&#xff08;上&#xff09; 一. 进制转换1. 二进制2. 二进制的转换 二. 原码 补码 反码三. 操作符的分类四. 结构成员访问操作符1. 结构体的声明2. 结构体成员访问操作符 一. 进制转换 1. 二进制 在学习操作符之前&#xff0c;我们先了解一些2进制、8进制、10进制…

魔众一物一码溯源防伪系统——守护品牌,守护信任!

在这个充满竞争的市场上&#xff0c;如何确保你的产品不被仿冒&#xff0c;如何赢得消费者的信任&#xff1f;魔众一物一码溯源防伪系统&#xff0c;为你提供一站式解决方案&#xff0c;守护你的品牌&#xff0c;守护消费者的信任&#xff01; &#x1f50d;魔众一物一码溯源防…

Node.js全栈指南:浏览器显示一个网页

上一章&#xff0c;我们了解到&#xff0c;如何通过第二章的极简 Web 的例子来演示如何查看官方文档。为什么要把查阅官方文档放在前面的章节说明呢&#xff1f;因为查看文档是一个很重要的能力&#xff0c;就跟查字典一样。 回想一下&#xff0c;我们读小学&#xff0c;初中的…

防火墙双机热备

防火墙双机热备 随着移动办公、网上购物、即时通讯、互联网金融、互联网教育等业务蓬勃发展&#xff0c;网络承载的业务越来越多&#xff0c;越来越重要。所以如何保证网络的不间断传输成为网络发展过程中急需解决的一个问题。 防火墙部署在企业网络出口处&#xff0c;内外网之…

windows系统修改克隆虚拟机的SID(报错:尝试将此计算机配置为域控制器时出错)

当我们用克隆虚拟机加入域的时候&#xff0c;可能会出现图下所示报错。这时我们可以用微软自带的工具sysprep来修改机器的SID来解决该问题 注意&#xff1a;用sysprep修改SID之后&#xff0c;系统会自动重启&#xff0c;之前配置好的网络、修改过的机器名会重置。所以&#xff…

6.2 通过构建情感分类器训练词向量

在上一节中&#xff0c;我们简要地了解了词向量&#xff0c;但并没有去实现它。在本节中&#xff0c;我们将下载一个名为IMDB的数据集(其中包含了评论)&#xff0c;然后构建一个用于计算评论的情感是正面、负面还是未知的情感分类器。在构建过程中&#xff0c;还将为 IMDB 数据…

Windows上PyTorch3D安装踩坑记录

直入正题&#xff0c;打开命令行&#xff0c;直接通过 pip 安装 PyTorch3D : (python11) F:\study\2021-07\python>pip install pytorch3d Looking in indexes: http://mirrors.aliyun.com/pypi/simple/ ERROR: Could not find a version that satisfies the requirement p…

JS(JavaScript)入门指南(DOM、事件处理、BOM、数据校验)

天行健,君子以自强不息;地势坤,君子以厚德载物。 每个人都有惰性,但不断学习是好好生活的根本,共勉! 文章均为学习整理笔记,分享记录为主,如有错误请指正,共同学习进步。 玉阶生白露,夜久侵罗袜。 却下水晶帘,玲珑望秋月。 ——《玉阶怨》 文章目录 一、DOM操作1. D…