0
在我的Django的看法,我正在嘗試從我的數據庫中的結果,然後把它們交給我的模板用下面的代碼:Django的 - 傳遞一個濾波的結果模板
f = request.GET.get('f')
try:
fb_friends_found= UserProfile.objects.filter(facebookid__in=f).values('facebookid')
i = fb_friends_found[0] #To get the dictionary inside of the list
results = i['facebookid'] #To retrieve the value for the 'facebookid' key
variables = RequestContext (request, {'results': results })
return render_to_response('findfriends.html', variables)
我進行的在'try'塊中使用manage.py shell的前三行很好,打印正確的'facebookid'。 不幸的是我無法讓它在我的瀏覽器中工作。有什麼建議麼?
感謝您的回答......我沒有得到任何錯誤或異常。該視圖由點擊按鈕觸發。當我點擊按鈕時沒有返回。但是,當我添加文字而不是變量:i = fb_friends_found [0]它工作正常。由於某種原因,它不喜歡:我= fb_friends_found [0] – Leon 2011-03-08 20:20:16
所以你的嘗試塊不掩蓋一個問題?視圖呈現,但沒有結果?我個人會開始在日誌中放入代碼,可以是'print fb_friends_found'或log。 – 2011-03-08 21:35:56
謝謝Yuji。我解決了這個問題......問題在於我是變量'f',好像它是一個列表 - 當它實際上是一個字符串時,將它與'facebookid'進行比較。我只是使用f.split(',')並解決了問題!謝謝你的幫助! – Leon 2011-03-13 13:38:52