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

138
Vistas
DRF Imagefield upload responds with html template instead of JSON

I'm working with Django Rest Framework 3.5.4 Django 1.9 python 3.5 and Angular 1.4.5. I'm having an issue where I can upload/post to an image endpoint but the response I get is the DRF template instead of the JSON that I was expecting.

models.py

class BeforeImage(models.Model):
    job = models.ForeignKey(Job, related_name='before_images')
    before_image = models.ImageField(upload_to='images/', default='images/no-image.jpg')

    def __str__(self):
        return self.pk

    class Meta:
        db_table = 'before_images'

serializers.py

class BeforeImageSerializer(ModelSerializer):
    before_image = ImageField(
        max_length=None, allow_empty_file=False, use_url=True)

    class Meta:
        model = BeforeImage
        fields = ('id', 'job', 'before_image')

views.py

class BeforeImageViewSet(ModelViewSet):
    queryset = BeforeImage.objects.all()
    serializer_class = BeforeImageSerializer

Payload

------WebKitFormBoundarybB5wAXF1Q6ZaG9pB Content-Disposition: form-data; name="job" 10 ------WebKitFormBoundarybB5wAXF1Q6ZaG9pB Content-Disposition: form-data; name="before_image"; filename="Screen Shot 2017-04-10 at 11.44.24 PM.png" Content-Type: image/png ------WebKitFormBoundarybB5wAXF1Q6ZaG9pB--

content-type

Content-Type:multipart/form-data;
about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

That's content negotiation and the preferred renderer when submitting forms is HTML because that's consistent with browsers.

If you want a JSON response, you should make sure your request set the headers so it gets JSON. In other words, you need to set the Accept headers to application/json

about 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