【发布时间】:2017-07-22 21:55:09
【问题描述】:
我在构建应用程序时遇到问题。基本上它的作用是如果它在字符串(submission.title)中检测到一个国家的名称,那么它将在标题之后打印该国家的国旗。因此,如果标题是“中国正在制造火箭”,那么它就会在火箭这个词之后印上中国国旗。 问题是它不会打印多个标志。因此,如果标题是“中国和俄罗斯正在制造火箭”,它只会打印中国国旗或俄罗斯国旗。不是都。我希望它能够打印两个标志。
谢谢
Python 脚本
news = []
i = 0
for submission in redditFunction(time, limit=int(num) ):
i += 1
for j in country: #j = country name
if j in submission.title:
flag = "static/flags/" + country[j].lower() + ".png"
news.append([str(i) + '. ' + submission.title, submission.url, flag] )
break
else:
news.append([str(i) + '. ' + submission.title, submission.url]) #no flag will be printed
return render_template("index.html", news=news)
HTML
{% for item in news %}
<h2> <a href= "{{item[1]}}">{{item[0]}}</a> <img src= "{{item[2]}}" style="width:25px;height:18.25px;"> </h2>
{% endfor %}
【问题讨论】:
标签: python python-3.x web flask praw