【发布时间】:2020-09-21 08:22:17
【问题描述】:
我是从 PHP 到 python。
在 PHP 中我这样做:
$result = array();
foreach($videos as $video) {
$result[] = array("title"=>$video->title,"description"=>$video->title);
}
print_r($result);
现在,当我在 python 烧瓶中尝试此操作时,我收到错误 很抱歉,但出了点问题:无法启动 Web 应用程序
result = {}
for video in videos:
title = video['title']
description = video['description']
content = {'title':title, 'description': description}
result[] = content
我该如何解决?
这里是完整的功能
@app.route("/add_channel", methods=['POST'])
def add_channel():
if request.method == "POST":
id=request.form['channel']
videos = get_channel_videos(id)
result = []
for video in videos:
result.append({'id': video['id'], 'title': video['snippet']['title']})
return result
【问题讨论】:
标签: python