@Vova135798

Как вытащить данные по одному?

Как сделать, чтобы выводилось не одной строчкой, а temp и city отдельно?
from flask import Flask, render_template
import requests

app = Flask(__name__)

@app.route('/')
def home():
    return render_template('home.html')

@app.route('/weather')
def index():
    key = 'b483b06e569a6bb4dc03ac0674c51d11'
    url = 'http://api.openweathermap.org/data/2.5/weather?q={},uk&units=metric&appid=' + key
    city = 'London'
    res = requests.get(url.format(city)).json()
    city_info = {
        'city': city,
        'temp': res["main"]["temp"],
    }

    context = {'info': city_info}

    return render_template('index.html', context = {'info': city_info})


if __name__ == "__main__":
    app.run(debug=True)


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>weather</title>
</head>
<body>
{{ context }}
</body>
</html>
  • Вопрос задан
  • 65 просмотров
Решения вопроса 1
SoreMix
@SoreMix Куратор тега Python
yellow
{{ context.info.city }}
{{ context.info.temp }}
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы