Heroku无法连接字体
Heroku can't connect fonts
我已经下载了 html 模板的字体,该模板使用 xhtml2pdf 转换为 pdf。我没能 google 找到适合我的答案。我认为路径已更改,但在 heroku bash 中路径未更改。这是我的代码:
字体在 invoices/static/invoices/fonts
settings.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。希望这会对某人有所帮助。
我已经下载了 html 模板的字体,该模板使用 xhtml2pdf 转换为 pdf。我没能 google 找到适合我的答案。我认为路径已更改,但在 heroku bash 中路径未更改。这是我的代码:
字体在 invoices/static/invoices/fonts
settings.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。希望这会对某人有所帮助。