django--提交資料並展示
阿新 • • 發佈:2021-08-30
django_提交資料並展示
- index.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <h1>建立個人資訊</h1> <form action="/userInfor/" method="post"> <p>姓名<input type="text" name="username"></p> <p>性別<input type="text" name="sex"></p> <p>郵箱<input type="text" name="email"></p> <p><input type="submit" value="submit"></p> </form> <hr> <h1>資訊展示</h1> <table border="1"> <tr> <td>姓名</td> <td>性別</td> <td>郵箱</td> </tr> {% for i in info_list %} <tr> <td>{{ i.username }}</td> <td>{{ i.sex }}</td> <td>{{ i.email }}</td> </tr> {% endfor %} </table> </body> </html>
- url.py
url(r'^userInfor/', views.userInfor)
- views.py
info_list=[] def userInfor(req): if req.method=="POST": username=req.POST.get("username",None) sex=req.POST.get("sex",None) email=req.POST.get("email",None) info={"username":username,"sex":sex,"email":email} info_list.append(info) return render(req,"userInfor.html",{"info_list":info_list})
本文來自部落格園,作者:Amfc_只敲程式碼不禿頭,轉載請註明原文連結:https://www.cnblogs.com/longloved/p/15207928.html