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/m.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燈, 水草

請輸入看板名稱,例如:e-shopping站內搜尋

TOP