django零基础项目实战-单位同事合乘的网页开发(五)
最后一天了,实现一下往数据库增加信息
{% extends 'index.html' %} {% block content %} <h1>创建个人信息</h1> <form action="/classes/" method="post"> <p>姓名<input type="text" name="name"></p> <p>性别<input type="text" name="sex"></p> <p>电话<input type="text" name="phone"></p> <p>地址<input type="text" name="address"></p> <p>公司<input type="text" name="company"></p> <p><input type="submit" value="submit"></p> </form> <hr> <h1>信息展示</h1> <table border="1"> <tr> <td>姓名</td> <td>性别</td> <td>电话</td> <td>地址</td> <td>公司</td> </tr> {% for i in info_list %} <tr> <td>{{ i.name }}</td> <td>{{ i.sex }}</td> <td>{{ i.phone }}</td> <td>{{ i.address }}</td> <td>{{ i.company }}</td> </tr> {% endfor %} {% endblock %}
def classes(req): if req.method == "POST": u = req.POST.get("name" ) s = req.POST.get("sex") p = req.POST.get("phone") a = req.POST.get("address") c = req.POST.get("company") models.Customer .objects.create( name=u, sex=s, phone=p, address=a, company=c ) info_list = models.Customer .objects.filter(company=c) return render(req,"classes.html", {"info_list": info_list}) return render(req, 'classes.html')
点提交以后
============================================================================
总结一下:真的是水平太低能力有限,以后学java的时候还会拿出来重做,啥也不会做起来很困难,坚持把这个做完也是不想没头没尾