Python flask TypeError:“ int”对象不可迭代

时间:2018-09-12 08:25:09

标签: python json flask

我收到以下错误:

TypeError: 'int' object is not iterable

我想做的是从json中获取一个简单的url数据,并通过Python Flask在网页上显示。

以下代码是:

@app.route('/data', methods=['GET'])
def data():
    params = {
    'api_key': '{API_KEY}',
    }
    url='https://xxx.xxx.xxx.xxx:xxxx/yy/yy/'
    r= requests.get(url, params=params, verify=False).content
    return render_template('data.html', time=json.loads(r)['time'])


html:

{% block body %}
<h1>data</h1>
 {% for ON in time %}
   <div>{{ON["time"]}}</div>
 {% endfor %}

1 个答案:

答案 0 :(得分:0)

您已创建Param( [string]$project, [string]$archive, [string]$config ) ##################################################################### # Functions # function Unzip { Param([string]$fname, [string]$output) if ($PSVersionTable.PSVersion.Major -ge 5) { Expand-Archive $fname $output -Force } else { & .\7za.exe x $fname -o"$output" -bb0 -bd -y } } ##################################################################### $current=(Get-Date).ToString("yyyy.MM.dd") $base_path="D:" $backup="$base_path\$project\bak-$current" echo "Deploying project $project" echo "Copy new binaries to: $base_path\$project\$current" Unzip $archive $base_path\$project\$current echo "Copying new config to: $base_path\$project\$current" Copy-Item "$config" -Destination "$base_path\$project\$current\" -Force echo "Creating log folder" New-Item "$base_path\$project\$current\logs" -type directory -force echo "Switch IIS physical path for website: $website" Import-Module WebAdministration Set-ItemProperty "IIS:\Sites\$website" -Name PhysicalPath -Value "$base_path\$project\$current" 。然后再次遍历模板中的time=json.loads(r)['time']变量。错误明确指出time是一个整数,不能进行迭代。因此,请看以下几行

time

尝试打印return render_template('data.html', time=json.loads(r)['time']) 是什么。肯定是整数。所以,我认为您可能只需要这样做

time