I want to render a list in a template

0

views.py

def main(request):
list=Hotel.objects.all()
template = get_template("index.html")
return HttpResponse(template.render({'list': list[0:max]}))

index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset='utf-8' />

  </head>
  <body>
    <ul>
    {% for hotel in list %}
    <li>{{ hotel }}</li>
    {% endfor %}
  </ul>

  </body>
</html>

The output I get is:

[<Hotel: Hotel object>, <Hotel: Hotel object>, <Hotel: Hotel object>, <Hotel: Hotel object>, <Hotel: Hotel object>, <Hotel: Hotel object>, <Hotel: Hotel object>, <Hotel: Hotel object>, <Hotel: Hotel object>, <Hotel: Hotel object>]

And I'd like to:

Hotel name 1

.Hotel name 2

    
asked by Diego Payo Martinez 28.04.2016 в 07:42
source

1 answer

3

Assuming that your Hotel model has an attribute called name (or name, or title ...) you would have to put:

<!DOCTYPE html>
<html>
  <head>
    <meta charset='utf-8' />

  </head>
  <body>
    <ul>
    {% for hotel in list %}
    <li>{{ hotel.nombre }}</li>
    {% endfor %}
  </ul>

  </body>
</html>

Since what you are asking yourself to render to you is the object itself.

You can see many examples of how to work with templates with Django in this link

    
answered by 28.04.2016 в 07:48