[Python] Show temperature in html

Discussão em 'Python' iniciado por Stack, Setembro 14, 2024.

  1. Stack

    Stack Membro Participativo

    I want the temperature to appear inside the div

    index.html

    <form action="/" method="POST">
    <input id='inputCity' name="inputCity" type="text" placeholder="Type", autocomplete="off">
    <button type="submit">Send</button>
    </form>
    <div> {{ temperature }}</div>


    main.py

    from flask import Flask, render_template, request, jsonify
    from weather_api import get_weather

    app = Flask(__name__)

    @app.route('/')
    def weather():
    return render_template('index.html', temperature=city_temperature)

    def input_data():
    city = request.form['inputCity']
    city_temperature = get_weather(city)


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


    I already tried changing to GET and I already tried creating another route

    Continue reading...

Compartilhe esta Página