Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

250
Vistas
How to return data from a table in a Django template

I am trying to display data from a website in HTML.

I have created a class called Video in models.py as follows:

class Video(models.Model):
    filename = models.CharField("File Name", max_length=100)
    title = models.CharField("Video Title", max_length=250)

The database is migrated and I am able to insert data into it using a Django form. I have checked and there is data in the database.

I have the following code in my HTML template file, but the page is empty when it is displayed, and is showing no data.

{% for video in Video %}
<div class="row">

    <div class="col-md-3">

        <a href="{{ video.filename }}">{{ video.title }}</a>

    </div>

</div>
{% endfor %}

Why isn't this displaying any data in the rendered HTML page?

Edit:

This is the relevant code from the view:

def listvideos(request):
    """Renders the listvideos page."""
    assert isinstance(request, HttpRequest)
    return render(
        request,
        'app/listvideos.html',

    )
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Templates can only render what you pass to them. You're not sending anything called Video, so you can't iterate over it.

return render(
    request,
    'app/listvideos.html',
    {'Video': Video.objects.all()}
)

You should consider whether you really want to call your parameter Video, though; it should probably be called videos both here and in the template.

(And please remove that assertion. For a start, it has no place in production code; and secondly the request will always be an HttpRequest, that is part of the contract for a view.)

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda