I know this might be a very stupid question, but i'm new to django and try to solve this problem for several houres now. I want to pass a variable from a html form to the backend an then use the variable there to make an api request. Then i want to pass the result of the api-request back to the index.html page.
For example:
index.html
<form action="#" method="post"> {% csrf_token %} <input type="text" class="form-control" id="city" placeholder="" value=""> <input type="submit" value="Submit"> </form> forms.py
import requests api_address='http://api.openweathermap.org/data/2.5/weather? appid=KEY&q=' city = FORM-VARIABLE url = api_address + city json_data = requests.get(url).json() kelvin = json_data['main']['temp'] temperature = round(kelvin - 273.15,0) And then show the temperature in the index.html
nameattribute. After that you can look at this question: stackoverflow.com/questions/4706255/…