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)
我使用manage.py shell在'try'块中执行了前三行,这样工作正常,打印正确的'facebookid'。 不幸的是我无法在浏览器中使用它。有什么建议?     
已邀请:
您是否遇到过您遇到的特定问题,例如异常? 如果你有一个没有except语句的try块,我觉得你应该得到某种异常。
try:
   # something
except Exception: # but be more specific
   print "exception occurred"
否则,代码看起来很好,如果浏览器中没有任何内容呈现,我会查看模板。除非......你在try块中隐藏了错误,在这种情况下你应该删除try块并让错误发生以理解错误。     

要回复问题请先登录注册