I have changed the url to: path('photos/', PhotoAlbumViewSet.as_view(), name='photos'),
And it solved the error that I mentioned above. But now I'm still getting the 406 Not Acceptable error: {"errors":[{"detail":"Could not satisfy the request Accept header.","status":"406","source":{"pointer":"/data"},"code":"not_acceptable"}]} Em sexta-feira, 30 de outubro de 2020 às 23:00:03 UTC-3, Kamilla Holanda escreveu: > Just tried and now I'm getting this error: > > AttributeError: type object 'AposentoFotoViewSet' has no attribute > 'get_extra_actions' > > > I have changed the code to: > > ------------------------------------------------------------------- > from rest_framework.generics import CreateAPIView > > class PhotoAlbumViewSet(CreateAPIView): > queryset = PhotoAlbum.objects.all() > serializer_class = PhotoAlbumSerializer > > def post(self, request, *args, **kwargs): > print("CREATE Photos") > ------------------------------------------------------------------- > > Is that the right package? > > Em sexta-feira, 30 de outubro de 2020 às 22:50:20 UTC-3, Wandss escreveu: > >> In your code I just saw this part: >> >> >> class MyUploadView(View): >> def get(self, request, **kwargs): >> print(request) >> print(request.method) >> print(request.GET) >> >> def post(self, request, **kwargs): >> pass >> >> Did you try this? >> >> >> class PhotoAlbumCreateAPIView(CreateAPIView): >> serializer_class = PhotoAlbumSerializer >> queryset = PhotoAlbum.objects.all() >> >> >> Em sex, 30 de out de 2020 22:42, Kamilla Holanda <holanda...@gmail.com> >> escreveu: >> >>> @Wandss Thank you for your answer! >>> >>> I am not sure If I understood what you mean. My client is an EmberJS app >>> and it fires a post request to upload the file and I think that the ViewSet >>> action to deal with a post request is the "create" action, right? Should I >>> deal with it using other action? >>> >>> >>> >>> >>> Em sexta-feira, 30 de outubro de 2020 às 22:35:12 UTC-3, Wandss escreveu: >>> >>>> Hi there. I'm not quite sure if this will solve the issue, but vou >>>> should be handling the upload as a post request. >>>> >>>> Em sex, 30 de out de 2020 22:32, Kamilla Holanda <holanda...@gmail.com> >>>> escreveu: >>>> >>>>> Hey there! >>>>> >>>>> I am working on a file upload functionality and right now I'm stucked >>>>> on a weird problem. I am always getting the error: >>>>> >>>>> >>>>> ------------------------------------------------------------------------------ >>>>> {"errors":[{"detail":"Could not satisfy the request Accept >>>>> header.","status":"406","source":{"pointer":"/data"},"code":"not_acceptable"}]} >>>>> >>>>> ------------------------------------------------------------------------------ >>>>> >>>>> >>>>> When I am sending the following request: >>>>> >>>>> >>>>> ------------------------------------------------------------------------------ >>>>> POST /aposento-fotos/ HTTP/1.1 >>>>> Host: localhost:8000 >>>>> Connection: keep-alive >>>>> Content-Length: 24364 >>>>> *Accept: application/json,text/javascript * >>>>> DNT: 1 >>>>> User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, >>>>> like Gecko) Chrome/86.0.4240.111 Safari/537.36 >>>>> *Content-Type: multipart/form-data; >>>>> boundary=----WebKitFormBoundaryvxVpkZTvYVihDGem * >>>>> Origin: http://localhost:4200 >>>>> Sec-Fetch-Site: same-site >>>>> Sec-Fetch-Mode: cors >>>>> Sec-Fetch-Dest: empty >>>>> Referer: http://localhost:4200/ >>>>> Accept-Encoding: gzip, deflate, br Accept-Language: >>>>> pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7 >>>>> >>>>> ------------------------------------------------------------------------------ >>>>> >>>>> >>>>> I am getting the following response: >>>>> >>>>> >>>>> >>>>> ------------------------------------------------------------------------------ >>>>> HTTP/1.1 406 Not Acceptable >>>>> Date: Sat, 31 Oct 2020 01:18:44 GMT >>>>> Server: WSGIServer/0.2 CPython/3.6.9 >>>>> *Content-Type: application/vnd.api+json * >>>>> Vary: Accept, Origin >>>>> Allow: GET, POST, HEAD, OPTIONS >>>>> X-Frame-Options: DENY >>>>> Content-Length: 138 >>>>> X-Content-Type-Options: nosniff >>>>> Access-Control-Allow-Origin: * >>>>> >>>>> ------------------------------------------------------------------------------ >>>>> >>>>> I have read about the DRF Parsers and tried it all. Nothing is working >>>>> for my view: >>>>> >>>>> >>>>> ------------------------------------------------------------------------------ >>>>> class MyUploadViewSet(ModelViewSet): >>>>> queryset = Photos.objects.all() >>>>> serializer_class = PhotosSerializer >>>>> permission_classes = [IsOwnerOrAdminUser] >>>>> parser_classes = [MultiPartParser, >>>>> FormParser, JSONParser, FileUploadParser] >>>>> >>>>> ------------------------------------------------------------------------------ >>>>> >>>>> >>>>> It only works when I use a generic view: >>>>> >>>>> >>>>> >>>>> ------------------------------------------------------------------------------ >>>>> class MyUploadView(View): >>>>> def get(self, request, **kwargs): >>>>> print(request) >>>>> print(request.method) >>>>> print(request.GET) >>>>> >>>>> def post(self, request, **kwargs): >>>>> pass >>>>> >>>>> ------------------------------------------------------------------------------ >>>>> >>>>> >>>>> But I want to get it working with the ModelViewSet. >>>>> >>>>> Does anybody know how could I get it working with ModelViewSet? I >>>>> think it's not working because the request *Content-Type*, but It was >>>>> supposed to work with a Parser, right? I am really confused and would >>>>> appreciate any help. >>>>> Thank you in advance. >>>>> >>>>> >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Django REST framework" group. >>>>> To unsubscribe from this group and stop receiving emails from it, send >>>>> an email to django-rest-fram...@googlegroups.com. >>>>> To view this discussion on the web visit >>>>> https://groups.google.com/d/msgid/django-rest-framework/b29de415-1908-40fa-b831-9080cb956c8bn%40googlegroups.com >>>>> >>>>> <https://groups.google.com/d/msgid/django-rest-framework/b29de415-1908-40fa-b831-9080cb956c8bn%40googlegroups.com?utm_medium=email&utm_source=footer> >>>>> . >>>>> >>>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Django REST framework" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to django-rest-fram...@googlegroups.com. >>> >> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/django-rest-framework/bdecd70d-bcd2-47c7-a35d-fcafce4fdb07n%40googlegroups.com >>> >>> <https://groups.google.com/d/msgid/django-rest-framework/bdecd70d-bcd2-47c7-a35d-fcafce4fdb07n%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >> -- You received this message because you are subscribed to the Google Groups "Django REST framework" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-framework+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-rest-framework/23731d8b-ad84-4bb3-907f-730e0a533a4bn%40googlegroups.com.