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

223
Vistas
How to add songs to my templates in views

if i post a song from my admin panel, i want the list of song to appear in the templates, i already created a models that allow me to post it, but i don't know how to create a views that allowed the song to appear in the templates, please how can i do this ?

this is my empty views views.py

from django.shortcuts import render
from .models import Audio

# Create your views here.
def index(request):
    return render(request, 'index.html')

this is my models.py i created models.py

from django.db import models

# Create your models here.
class Audio(models.Model):
    book_title = models.CharField(max_length=100, null=False, blank=False)
    file = models.FileField(upload_to='file')
    author = models.CharField(max_length=100, null=False, blank=False)
    artist = models.CharField(max_length=100, null=False, blank=False)
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You pass a queryset of Audio objects to the template:

# Create your views here.
def index(request):
    context = {'songs': Audio.objects.all()}
    return render(request, 'index.html', context)

in the template we can enumerate over the songs:

{% for audio in songs %}
    {{ audio.book_title }} by {{ audio.artist }} </br>
{% endfor %}
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