Skip to main content
simples cambios
Origen Enlace
Angel Angel
  • 10.1k
  • 9
  • 44
  • 69

--views.pyviews.py

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

---index.htmlindex.html

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

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

  </body>
</html>

La salida que obtengo es :

[<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>]

Y me gustaria:   

. Nombre hotel 1   

.Nombre hotel 2

--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>

La salida que obtengo es :

[<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>]

Y me gustaria:  . Nombre hotel 1  .Nombre hotel 2

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>

La salida que obtengo es :

[<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>]

Y me gustaria: 

. Nombre hotel 1 

.Nombre hotel 2

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

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

---index.html

    {% for hotel in list %}
  • {{ hotel }}
  • {% endfor %}
<!DOCTYPE html>
<html>
  <head>
    <meta charset='utf-8' />

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

  </body>
</html>

La salida que obtengo es : [<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>]

[<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>]

Y me gustaria: . Nombre hotel 1 .Nombre hotel 2

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

    {% for hotel in list %}
  • {{ hotel }}
  • {% endfor %}

La salida que obtengo es : [<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>]

Y me gustaria: . Nombre hotel 1 .Nombre hotel 2

--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>

La salida que obtengo es :

[<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>]

Y me gustaria: . Nombre hotel 1 .Nombre hotel 2

Origen Enlace

Quiero renderizar una lista en un template

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

    {% for hotel in list %}
  • {{ hotel }}
  • {% endfor %}

La salida que obtengo es : [<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>]

Y me gustaria: . Nombre hotel 1 .Nombre hotel 2