Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

136
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!