I'm trying to return a uploaded file to the Client.
models.py
file = models.FileField(_('file'), db_index=True, null=True, blank=True, upload_to='files/')
views
class ContentInfoViewSet(viewsets.ModelViewSet):
queryset = ContentInfo.objects.all()
serializer_class = ContentInfoSerializer
http_method_names = ['get']
@detail_route(methods=['get']) //this is just for testing
def files(self, request, pk=None):
return Response(pk, status=status.HTTP_200_OK)
Here I was just trying with a "files" route.
When I try to get "content-info". It works nicely:
[
{
"url": "http://127.0.0.1:8000/users/content-info/1/",
"id": 1,
"date": "2017-01-27T16:21:41.976289Z",
"title": "Hey Hey",
"image_url": "",
"content_url": "",
"file": null
},
{
"url": "http://127.0.0.1:8000/users/content-info/3/",
"id": 3,
"date": "2017-03-21T12:09:32.984119Z",
"title": "NWE",
"image_url": "",
"content_url": "",
"file": "http://127.0.0.1:8000/users/content-info/files/BIAM-51.pdf"
}
]
But that URL doesn't work. Even if I make a get with Authorization. I don't know what I'm doing wrong. It doesn't find the page. And it's logic, because it's not in the urls.py (I mean http://127.0.0.1:8000/users/content-info/files/BIAM-51.pdf)
This solution would be great: pdf
when you open the link, it shows the pdf. I thought that it would happen when I follow this link "http://127.0.0.1:8000/users/content-info/files/BIAM-51.pdf"