Django: show all the variables in a template

0

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?

    
asked by Carlos GR 26.10.2016 в 11:04
source

2 answers

1

I answer to myself: To see everything that is passed to a template can be used in the template {% debug %}

This only works if in settings.py it is DEBUG = True

    
answered by 26.10.2016 / 12:27
source
1

To avoid errors use the following script to assign the value to DEBUG: settings.py

DEBUG = False
import sys
RUNNING_DEVSERVER = (len(sys.argv) > 1 and sys.argv[1] == 'runserver')
if RUNNING_DEVSERVER == True:
    DEBUG = True
    
answered by 26.10.2016 в 18:37