1👍
Since this is number 2 place in Google for this question (after an issue in django-easy-pdf
), here’s a solution.
This is the code that supplies the font files:
if settings.STATIC_URL and uri.startswith(settings.STATIC_URL):
path = os.path.join(settings.STATIC_ROOT, uri.replace(settings.STATIC_URL, ""))
elif settings.MEDIA_URL and uri.startswith(settings.MEDIA_URL):
path = os.path.join(settings.MEDIA_ROOT, uri.replace(settings.MEDIA_URL, ""))
else:
path = os.path.join(settings.STATIC_ROOT, uri)
So, your font must be either in STATIC_ROOT or MEDIA_ROOT on the server’s filesystem. Which means:
1) Add the font to static files of your project (assuming your static files are set up properly).
2) Important: run python manage.py collectstatic
, so the file is actually copied there, even if you run the development server.
3) If you:
- placed your font into
static/fonts/awesomefont.ttf
of your project - your
STATIC_URL
is, say/static_files/
Then you can use either of those:
/* Relative to static files' root */
@font-face { font-family: Awesome; src: url(fonts/awesomefont.ttf); }
/* Full static URL */
@font-face { font-family: Awesome; src: url(/static_files/fonts/awesomefont.ttf); }
Again, please note – the font will be loaded by xhtml2pdf
utility, not the browser, so those files must be local to the machine Django is running on.
👤Xan
Source:stackexchange.com