[問題] Django 小小問題..

看板Python作者 (JimmyG)時間14年前 (2011/04/20 16:28), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串1/1
雖然是小小問題,不過我自己解決不了想要麻煩板友 目前想要用 django 寫一個簡單的搜尋程式 流程大致上是這樣: 在 views.py 裡面有兩個 methods def IndexSearch(request): inputString = request.GET.get('inputString', '') return render_to_response('index.html', {'inputString' : inputString}) def SearchResult(request): inputString = request.POST['inputString'] # 這邊會利用 inputString 去跑其他程式 return render_to_response('result.html', {'inputString' : inputString}) 另外在 url.py 中 url(r'^index', 'IndexSearch'), url(r'^indexresult', 'SearchResult'), 最後在 template 裡面 index.html 使用 <form method = "GET" action = "/indexresult"></form> 想請問 1. 為什麼我在 index 中點選搜尋按鈕把 form 的東西送出去 頁面不會導向 result.html 2. 為什麼 view.py 的 SearchResult 都抓不到 inputString 的資料 是哪邊寫錯了嗎? 找很久找不到..謝謝各位看完文章,以及謝謝回答了。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.45.232.26

04/20 19:53, , 1F
2. 把form改用post試試看囉 1.要先確定是不是有順利跑完
04/20 19:53, 1F

04/21 03:08, , 2F
使用 Form 解決了!
04/21 03:08, 2F
文章代碼(AID): #1DhfaYX2 (Python)
文章代碼(AID): #1DhfaYX2 (Python)