zoukankan      html  css  js  c++  java
  • 获取表单信息并添加

    前端代码如下:

    <form  action="/addbook/" method="post">
    书本名称:<input type="text" name="name"><br/>
    书本价格:<input type="text" name="price"/><br/>
    更新日期:<input type="date" name="pub_date"><br/>
    作者:<input type="text" name="author"/><br/>
    <input type="submit" value="添加书本信息"/>
    </form>
    addbook方法用来出来表单添加,代码如下:
    def  addbook(request):
    if request.method=="POST":
    name=request.POST.get("name")
    price=request.POST.get("price")
    pub_date=request.POST.get("pub_date")
    author=request.POST.get("author")
    Book.objects.create(name=name,price=price,author=author,pub_date=pub_date)
    #全部添加Book.objects.create(**dic)
    return HttpResponse("添加成功")
    运行以后出现下面的提示:

    在页面中添加下面的代码用于处理这个问题:

    再次运行提示添加成功,查看数据库,确认数据已经添加

    
    
  • 相关阅读:
    mac lsof使用查看端口
    mac 安装gevent报错
    vim命令学习
    linux批量关闭进程
    坐标点转换
    screen命令记录
    hashlib模块
    PyYAML和configparser模块讲解
    xml处理模块
    json、pickleshelve模块(超级好用~!)讲解
  • 原文地址:https://www.cnblogs.com/woshinige/p/9968966.html
Copyright © 2011-2022 走看看