I have my django app hosted on pythonanywhere. I am using weasyprint to generate a pdf and there is an image to be shown in my pdf. The error in the error log is "Failed to load image at /static/images/logo.png". When I try to open the same path as url, it shows me the image in the browser. Which means it is getting the path right but something else is wrong.
I have my static directory placed outside the app. And this path is added to the settings file.
My folder structure:
my_app
static
|__ css
|__ images
|__ logo.png
|__ js
templates
|__ my_app
|__ pdf.html
settings.py:
STATIC_DIR = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
STATICFILES_DIRS =[
STATIC_DIR,
]
pdf.html:
{% load static %}
<td><img class="my_logo" src="{% static 'images/logo.png' %}" alt="Temporarily Unavailable"></td>
Are you trying to make a pdf for the user to download, or are you trying to display a html file?
If you are using weasyprint to generate a pdf, then weasyprint will not try to access http://yourwebsite/static/images/logo.png
to get the logo to put into the pdf. Instead it will try to access the file on your server at /static/images/logo.png
.
If all you want to do is to have the logo in your pdf, you should instead get weasyprint to say put in the logo from /home/username/path/to/your/logo/file.png
instead.