@login_required
def download_invoice(request, pk):
 invoice = get_object_or_404(Invoice, pk=pk)
 if (not invoice.ref):
  raise Http404('No reference!')
 if (invoice.billing.user != request.user):
  raise PermissionDenied('Not an owner!')
 filename = invoice.filename
 path = os.path.join(appsettings.INVOICE_PATH, filename)
 if (not os.path.exists(path)):
  raise Http404('File {0} does not exist!'.format(filename))
 with open(path, 'rb') as handle:
  data = handle.read()
 response = HttpResponse(data, content_type='application/pdf')
 response['Content-Disposition'] = 'attachment; filename={0}'.format(filename)
 response['Content-Length'] = len(data)
 return response

@ login_required def download_invoice ( request , pk ) : invoice = get_object_or_404 ( Invoice , pk = pk ) if ( not invoice . ref ) : raise Http404 ( 'No reference!' ) if ( invoice . billing . user != request . user ) : raise PermissionDenied ( 'Not an owner!' ) filename = invoice . filename path = os . path . join ( appsettings . INVOICE_PATH , filename ) if ( not os . path . exists ( path ) ) : raise Http404 ( 'File {0} does not exist!' . format ( filename ) ) with open ( path , 'rb' ) as handle : data = handle . read ( ) response = HttpResponse ( data , content_type = 'application/pdf' ) response [ 'Content-Disposition' ] = 'attachment; filename={0}' . format ( filename ) response [ 'Content-Length' ] = len ( data ) return response
download invoice pdf .