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'。
不幸的是我无法在浏览器中使用它。有什么建议?
没有找到相关结果
已邀请:
1 个回复
徘廷
否则,代码看起来很好,如果浏览器中没有任何内容呈现,我会查看模板。除非......你在try块中隐藏了错误,在这种情况下你应该删除try块并让错误发生以理解错误。