Let's create a web form with a text input element to allow the user to specify their given zip code. In the templates directory, add a new HTML file called "weather_form.html" and place inside the following contents:
Here we're saying when the user submits the form, we'll send their form inputs via POST request to a route called "/weather/forecast". So let's update our weather routes accordingly:
Based on this routing logic, after we get a weather forecast for the given zip code, we'll send the results to a new page called "weather_forecast.html", so let's create that page now in the "templates" directory, and place inside the following contents:
{% extends "layout.html" %}
{% block content %}
<h2>Weather Forecast for {{ results["city_name"] }}</h2>
<p>Zip Code: {{ zip_code }}</p>
<!-- TODO: consider using a table instead of a list -->
<!-- TODO: consider adding images using the provided icon urls -->
<ul>
{% for forecast in results["hourly_forecasts"] %}
<li>{{ forecast["timestamp"] }} | {{ forecast["temp"] }} | {{ forecast["conditions"].upper() }}</li>
{% endfor %}
</ul>
{% endblock %}
Here, we are using the Jinja template language to loop through our forecasts and display each.
Restart the server and visit the following routes to test the newly-integrated weather forecasting functionality: