Encountering file not found error in production
I hosted my django project on vercel, every static file is working correctly. django views.py function
def view_pdf(request):
file_path = os.path.join(settings.BASE_DIR, 'static', 'media', 'Shashank_Joshi_resume.pdf')
with open(file_path, 'rb') as pdf:
response = HttpResponse(pdf.read(), content_type='application/pdf') instead of mimetype
response['Content-Disposition'] = 'inline; filename="Shashank_Joshi_resume.pdf"'
return response
html template
<div class="resume">
<input type="button" value="Resume" class="btn btn-primary" onclick="window.open('view_pdf')">
</div>
error im getting FileNotFoundError at /view_pdf [Errno 2] No such file or directory: '/var/task/static/media/Shashank_Joshi_resume.pdf'
But i have button in my html template by which a pdf file is shown when i click that its showing file not found error on vercel but when i run it locally its working totally fine. The github repo is also upto date.
Did you set MEDIA_ROOT in your settings.py? check it
As ruddra said, run your collectstatic
At the end you can debug your code, like print your file_path
I hope this helps