zoukankan      html  css  js  c++  java
  • 编辑出版社:

    views:

    #定义编辑功能:
    def edit_publisher(request):
    #获取要编辑对象的id:
    pk = request.GET.get("id")
    obj = models.Publisher.objects.filter(pk = pk).first()
    #判断如果不是真的话返回要展示的页面:
    if not obj:
    return HttpResponse("所查询的数据不存在")
    if request.method == "POST":
    pub_name = request.POST.get("pub_name")
    # obj.name = pub_name #内存中修改了属性
    # obj.save() #提交保存
    if models.Publisher.objects.filter(name=pub_name):
    return render(request,"edit_publisher.html",{{"error":"出版社名称已存在"}})
    models.Publisher.objects.filter(pk = pk).update(name=pub_name)
    #重定向到展示页面:
    return redirect("/publisher/")
    return render(request,"edit_publisher.html",{"obj":obj})

    HTML:
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Title</title>
    </head>
    <body>

    <form action="" method="post">
    <p>
    出版社名称:<input type="text" name="pub_name" required value="{{ obj.name }}"><span>{{ error }}</span>
    </p>

    <button>提交</button>
    </form>

    </body>
    </html>
  • 相关阅读:
    洛谷P3796
    cf1291c-Mind Control
    莫比乌斯函数
    C. Mixing Water(三分)
    E. Modular Stability(思维构造)
    【美团杯2020】平行四边形
    原根定义
    E. Are You Fired?(思维)
    102606C. Coronavirus Battle time limit per test4 seconds(三维拓扑序)
    E
  • 原文地址:https://www.cnblogs.com/zhang-da/p/12037395.html
Copyright © 2011-2022 走看看