Wednesday 15 June 2011

python - Why image upload to django rest framework endpoint returns 0 NO RESPONSE? -



python - Why image upload to django rest framework endpoint returns 0 NO RESPONSE? -

i have created endpoint in django rest framework , want authenticated users can create , alter data. im using token authentication.

when seek update profile_picture of testik instance (via patch method) providing right credential. (authorization = token xxxxxxxxxxxxx), works, profile_picture updated , status code 200 returned.

but whenever credentials wrong or missing, doesnt homecoming error 401 (unauthorized) see in django terminal output: "patch /api/testik/1 http/1.1" 401 59" "status 0 no response"

so have model:

from django.db import models # create models here. class testik(models.model): email = models.emailfield('email address', unique=true, db_index=true) first_name = models.charfield(max_length=50, blank=true) profile_picture = models.imagefield(upload_to='photos/testik',blank=true)

with associated serializer:

from models import testik rest_framework import serializers class testikserializer(serializers.hyperlinkedmodelserializer): class meta: model = testik fields = ('url', 'profile_picture','first_name')

and viewset:

from django.shortcuts import render serializers import testikserializer models import testik rest_framework import mixins,permissions,viewsets,parsers # create views here. class testikviewset(mixins.retrievemodelmixin, mixins.updatemodelmixin, mixins.listmodelmixin, mixins.createmodelmixin, mixins.destroymodelmixin, viewsets.genericviewset): permission_classes = (permissions.isauthenticatedorreadonly,) serializer_class = (testikserializer) queryset = testik.objects.filter() parser_classes = (parsers.multipartparser,parsers.jsonparser)

does have indea did wrong or http request (maybe specific content type / tried multipart or something) should utilize please?

for file uploads need utilize multipart/form-data content type.

additionally patch verb won't typically back upwards file uploads. you'll need utilize put (replace) or post (create) handle that.

python django http django-rest-framework

No comments:

Post a Comment