我有一个将 3 个项目传递给 HTML 页面的元组,我希望它传递第四个。我已经在网上阅读了要做到这一点,我必须将我的元组变成一个列表,但我试过了,但仍然没有得到任何东西(没有错误,对象最后没有出现) . 所以为了清楚起见,我把它藏起来了。
我正在尝试将“maybe_existing_user.fb_pic”添加到“详细信息”元组中。
PYTHON
@app.route('/results/<int:id>')
def results(id):
rate = 0 # either 0 or num/total
article_list_of_one = Article.query.filter_by(id=id)
a_obj = article_list_of_one[0]
avs_obj = retrieve_article_vote_summary(a_obj.id) # vote_summary is a list of [tuples('True', numOfTrue), etc]
total_votes = avs_obj.getTotalVotes()
vote_choices = []
vote_choice_list = VoteChoice.getVoteChoiceList()
for item in vote_choice_list: # looping over VoteChoice objects
num = avs_obj.getVoteCount(item.choice)
if total_votes > 0: # protecting against no votes
rate = num/total_votes
vote_choices.append([item.choice, item.color, num, rate*100, total_votes])
details = avs_obj.getVoteDetails() # 10/02 - retrieve array of tuples [(user, VoteChoice, Comments)]
print("Inside results(" + str(id) + "):")
details_count = 0
for detail in details:
maybe_existing_user = User.query.filter_by(name=detail[0]).first()
detail += (maybe_existing_user.fb_pic,)
print(detail)
#print(" " + str(details_count) + ": " + details[0] + " " + details[1] + " " + details[2])
details_count += 1
return render_template('results.html', title=a_obj.title, id=id,
image_url=a_obj.image_url, url=a_obj.url,
vote_choices=vote_choices, home_data=Article.query.all(),
vote_details=details)
HTML
<!DOCTYPE html>
<html>
<body>
{% for detail in vote_details %}
<strong>User:</strong> {{ detail[0] }} <strong>Vote:</strong> {{ detail[1] }} <strong>Comments:</strong> {{ detail[2] }}<br>
{{ detail[3] }}
{% endfor %}
</body>
</html>
潇湘沐
拉风的咖菲猫
哈士奇WWW
ABOUTYOU
相关分类