I have the following function that returns a JSON:
class HotelService(models.Model):
def get_avail_and_rates(self, rq):
cabeceras = {
'Content-Type': 'application/json',
'action': 'getavailandrates',
'format': 'json',
'Accept-Encoding': 'gzip'
}
url = 'http://connectivity.dingus-services.com/services/v4/hotelservice.ashx'
response = requests.post(url, data=rq, headers=cabeceras)
if response.status_code == 200:
results = response.json()
else:
results = "Error"
return results
In views.py I call the function passing the parameters and the result is passed to a template
hs = HotelService()
hotels_list = hs.get_avail_and_rates(rq)
template = loader.get_template('prueba.html')
return render(request, 'prueba.html', hotels_list)
At the time of painting it in prueba.html I do the following:
{% for result in hotels_list %}
<p>{{ result }}</p>
{% endfor %}
This does not return anything. I have tried it in many ways but I can not show the data. How would you show it? And another question: Is there any way to see what a function returns before displaying it in a template?