Django Python does not display the correct PDF file -
i have pdf files stored on server. writing code prompts users download pdf file. used following code:
filename ="somepdf.pdf" filedir = "media/" filepath = os.path.join( filedir, filename ) pdf=open(filepath) response = httpresponse(pdf.read(),content_type='application/pdf') response['content-disposition'] = 'attachment;filename=%s' % filename return response
for reason, rechecked pdf file prompted. pdf file not readable (corrupted file perhaps).
do know happen?
you have missed media_root:
from settings import media_root ... filepath = os.path.join(media_root, filedir, filename)
Comments
Post a Comment