I have manually added few pdf in media folder. when i send the response url to be displayed onto a embed tag, while inspecting, the src is been shown successfully, but the pdf is not been displayed. (Note: i do not have any model. Using an external AD for login.) seems to be working while the file is served from static.
STATIC_URL = ‘/static/’
STATICFILES_DIRS = [
os.path.join(BASE_DIR)
]
STATIC_ROOT = os.path.join(BASE_DIR, ‘texteditor/static/’) # Directory for collected static files in production
MEDIA_URL = ‘/media/’ # URL for accessing media files
MEDIA_ROOT = os.path.join(BASE_DIR, ‘media’) # Absolute path to the media directory
We’re going to need more details before we can help.
Is this in your development environment, or a production deployment?
If this is in development, are you using runserver?
If this is in a production deployment, please identify the server you are using.
Please provide the full path and file name of the file you’re trying to display, and show the template where you are trying to display it.
(Side note: It really is not a good idea to have your STATIC_ROOT and MEDIA_ROOT in your project directory structure in a production-quality deployment.)
Good day sir, @KenWhitesell , This is for production deployment. using nginx and uwsgi.
path for media dir:
pixscribe/media
path for pdf file:
pixscribe/media/sample.pdf
path for app dir:
pixscribe/texteditor/
nginx conf:
# Django media and static files
location /media {
alias /home/pythoner/pixscribe/media;
}
location /static {
alias /home/pythoner/pixscribe/texteditor/static;
}
Only possible solution seems to be providing the pdf in a static location.
Loading from static: relative_path = static(f’{folder}.pdf’)
passing this as a response seems to be loading the pdf in embed tag.
Is the view code you are using setting the correct mime type for the pdf file?
You can check the difference (if any) in mime type and other response headers by using your browser’s network inspector while loading the same file both from the view and from static files.