New Publisher:

views:

# Press to increase the definition of function: 
DEF add_publisher (Request):
IF request.method == "POST":
Data # get user submitted:
pub_name = request.POST.get ( "pub_name")
# Press to determine whether the name already exists
models.Publisher.objects.filter IF (= the pub_name name):
return the render (Request, "add_publisher.html", { "error": "Press name already exists"})
# insert data into the database name equal to the input name name:
obj = models.Publisher.objects.create (name = pub_name)
Print (obj.pk)
Print (obj.name)
# show Jump to page:
return redirect ( "/ Publisher /")
return the render (Request, "add_publisher.html")
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><span>{{ error }}</span>
</p>

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

</body>
</html>

Guess you like

Origin www.cnblogs.com/zhang-da/p/12037167.html