Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

254
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda