Heroku无法连接字体



我已经下载了html模板的字体,该模板使用xhtml2pdf转换为pdf。我没能在谷歌上找到对我有用的答案。我以为路径已经改变了,但在heroku bash中,路径并没有改变。这是我的代码:

字体在发票/静态/发票/字体中

设置.py

STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'main/static'),
#os.path.join(BASE_DIR, 'invoices/static'),
#BASE_DIR / "static",
]
STATIC_ROOT os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_STORAGE = 'whitenoise.storage. CompressedManifestStaticFilesStorage'

html字体连接

<html lang="ru">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html" >
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Инвойс #{{invoice_id}}</title>
<style>
@font-face {
font-family: 'Roboto-Medium';
src: url(../invoices/static/invoices/fonts/Roboto-Medium.ttf);
}
</style>

因此,当部署在heroku上时,必须使用/path_to_fonts而不是/path_to_fonts。希望这能帮助到别人。

最新更新