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

267
Vistas
How can I show my images through JsonResponse in Django's view?

I have a question, my collaborator's code works well, it shows some images that were previously uploaded through an input through a modal. The problem is that I want to display the images in a detail view. I modified it and I can only show one of the 10 that were uploaded. How can I show all 10? I have no idea how to handle that JSON he used

views.py


class detail_carro(DetailView):
    template_name = 'carros/carros-detail.html'
    queryset=Carro.objects.all()
    context_object_name = 'carros'


def create_carros_picture(request):

        if request.FILES['files']:
            file = request.FILES['files']
            fs = FileSystemStorage()  # defaults to   MEDIA_ROOT
            new_name = "picture"
            new_name = fs.get_valid_name(new_name)+".jpg"
            filename = fs.save(new_name, file)
            return JsonResponse({filename:file.name},safe=False)
        else:
            form=CarroForm()
            return render(request, "carros/carros-form-add.html",{'form':form})


def create_carros_warranty(request):
    if request.FILES['files']:
        file = request.FILES['files']
        fs = FileSystemStorage()  # defaults to   MEDIA_ROOT
        ext = file.name.split('.')[-1]
        new_name = "warranty"
        new_name = fs.get_valid_name(new_name) + '.' + ext
        filename = fs.save(new_name, file)
        return JsonResponse({filename: file.name}, safe=False)
    else:
        form = CarroForm()
        return render(request, "carros/carros-form-add.html", {'form': form})
 

carros-detail.html

{% if carros.new_name %}
<a data-id="{{carros.id}}" class="btn_view_gallery">
<img src="{% get_media_prefix %}{{carros.new_name}}" height="300">
</a>
{% endif %}

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The DetailView is used to show only a single model instance, Carro in your case I think.

To show all model instaces, use the generic ListView.

https://docs.djangoproject.com/en/4.0/ref/class-based-views/generic-display/#listview

views.py

class CarroListView(ListView):
    template_name = 'carros/carros-list.html'
    queryset=Carro.objects.all()
    context_object_name = 'carros'

carros/carros-list.html

{% for carro in carros %}
<a data-id="{{carros.id}}" class="btn_view_gallery">
<img src="{% get_media_prefix %}{{carros.new_name}}" height="300">
</a>
{% endfor %}
about 4 years ago · Juan Pablo Isaza 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