Hi, any suggestions to download a pdf file I have the following model where I keep the files:
class Archivo(models.Model):
archivo_pdf = models.BinaryField(null=True, blank=True)
nombre = UCharField(max_length=30, null=True, blank=True)
I am trying to download the file as follows:
@login_required
@api_view(['GET'])
def download_file(request,id):
try:
archivo = get_object_or_404(Archivo, id=id)
contents = archivo.archivo_pdf
name_file = archivo.nombre
response = HttpResponse(contents)
response['Content-Disposition'] = 'attachment; filename={}'.format(name_file)
return response
except Exception as e:
if type(e) is Http404:
return Response(False, status=status.HTTP_404_NOT_FOUND)
else:
return Response({"detail": str(e)}, status=status.HTTP_400_BAD_REQUEST)
When calling the route link , I get the following error message:
DjangoUnicodeDecodeError