Python 板


LINE

我其实不太知道我的问题属於python还是html5 但我是参考python的书,所以想说发在这里 看我以下的内容可能有人已经知道是哪本书了 我想要做的功能是输入表格的值,并且将表格的值累计显示在上面 这是书籍上的范例 但{%for c in r.comment_set.all %} 这行我不太懂,专案中app的名称为restaurant 所以这个r指的是restaurant吗? 以及他的c in r.comment_set.all 因为用c in r.comment,所以之後的内容才可以是{{c.visitor}}? 还有他的set.all是甚麽意思?是指该评价功能上应该输入的都有输入完全? 还有他是用for 回圈来依序显现在上面的吗? comment为我在views中define的东西,height也是 <table> <tr> <th>留言者</th> <th>时间</th> <th>评价</th> </tr> {% for c in r.comment_set.all %} <tr> <td> {{c.visitor}} </td> <td> {{c.date_time1|date:"F j,Y" }} </td> <td> {{c.content}} </td> </tr> {% endfor %} </table> <form atcion="" method="post">{% csrf_token %} <table> <tr> <th><label for="id_visitor">留言者:</label></th> <td> {{f.visitor}} </td> <td> {{f.visitor.errors}} </td> </tr> <tr> <td><label for="id_email">电子信箱:</label></td> <td> {{f.email}} </td> <td> {{f.email.errors}} </td> </tr> <tr> <td><label for="id_content">评价:</label></td> <td> {{f.content}} </td> <td> {{f.content.errors}} </td> </tr> </table> <input type="submit" value="给予评价"> </form> 希望的结果: 留言者 时间 评价 user 八月 19,2016 123456 s890269 九月 2,2016 我没意见~~ s890269 九月 2,2016 我没意见!! ---------------------------------------- 以下为表格: 留言者: 电子信箱: 评价: 给予评价(按此按钮输入评价,然後会依序显示在上面) 这是我参考照打的 views: def height(request): if request.POST: f1=HeightForm(request.POST) if f1.is_valid(): cushion=f1.cleaned_data['cushion'] faucet=f1.cleaned_data['faucet'] date_time=timezone.localtime(timezone.now()) h = Height.objects.create( cushion=cushion, faucet=faucet, date_time=date_time, ) f1=HeightForm() else: f1=HeightForm() return render_to_response('height.html', RequestContext(request,locals())) form: class HeightForm(forms.Form): cushion=forms.CharField(max_length=2) faucet=forms.CharField(max_length=2) models: class Height(models.Model): date_time=models.DateTimeField('date published') cushion=models.CharField(max_length=255) faucet=models.CharField(max_length=255) def __unicode__ (self): return self.name <table> <tr> <th>时间</th> <th>坐垫高度</th> <th>龙头高度</th> </tr> {%for h in r.height_set.all %} <tr> <td> {{h.date_time|date:"F j,Y" }} </td> <td> {{h.cushion}} </td> <td> {{h.faucet}} </td> </tr> {% endfor %} </table> <form atcion="" method="post">{% csrf_token %} <table> <tr> <th><label for="id_cushion">坐垫高度:</label></td> <td>{{f1.cushion}}</td> </tr> <tr> <th><label for="id_faucet">龙头高度:</label></td> <td>{{f1.faucet}}</td> </tr> </table> <input type="submit" value="纪录"> </form> 但我按了之後,却没有显示在上面 不太知道是有什麽问题,程式码应该是没问题 因为网页有成功跑出来 应该说,我想问的是 他能够让提交的讯息都显示在上面的关键是什麽? 我有漏打吗? --



※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 218.164.162.219
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1472754395.A.4EB.html
1F:→ h5904098: 上面那个范例是comment有foreignkey关系才那样用吧 但 09/02 12:28
2F:→ h5904098: 你只有height一个model 直接for h in height 就可以显 09/02 12:28
3F:→ h5904098: 示了吧? 09/02 12:28
4F:→ s890269: 没有办法欸,一样只有页面刷新,没有值 09/02 14:02
5F:→ s890269: 会是因为要height_set.all? 09/02 14:22
6F:→ h5904098: 应该是你render的context里没有Height.objects.all() ? 09/02 16:57
7F:→ h5904098: 应该不是用_set.all 09/02 17:03
8F:→ h5904098: 你Height=Height.objects.all()有render进去 09/02 17:03
9F:→ h5904098: 直接for h in height 就有东西了吧? 09/02 17:04







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:Tech_Job站内搜寻

TOP