[英]How to add custom font in python-flask?
我嘗試過使用@fontface css樣式,但字體不會被渲染。 有沒有其他方法使用python / flask?
<!DOCTYPE html>
<html>
<style type="text/css">
@font-face {
font-family: trial;
src: url_for('CENTRALESANSCND-BOLD.otf') ;
font-weight:bold; }
</style>
<body>
<p style="font-family:trial; font-weight: bold"> Hello </p>
</body>
</html>
以上是我的HTML模板。 不幸的是,當我使用Flask渲染它時,它不會反映字體。 以下是我的.py代碼:
from flask import Flask, render_template
app=Flask(__name__)
app.secret_key='1234'
@app.route('/', methods=['post', 'get'])
def output():
c=2+3
print c
return render_template('f.html', c=c)
if __name__=='__main__':
app.run(port=9876)
非常感謝您的幫助..所有建議的組合終於奏效了。
在這里發布解決方案:
CSS文件:
@font-face{
font-family: trial;
src: url('CENTRALESANSCND-BOLD.otf');
font-weight: bold;}
body {font-family: georgia; color:green}
h1 {font-family:trial; color: pink}
HTML文件:
<!DOCTYPE html>
<html>
<link type="text/css" rel="stylesheet" href="{{url_for('static', filename='mystyle.css')}}"/>
<body>
<p > Hello... </p>
<h1> welcome </h1>
</body>
</html>
url_for接受一個函數名稱,你需要用雙花括號括起來...嘗試:
<style type="text/css">
@font-face {
font-family: trial;
src: {{ url_for('static', filename='CENTRALESANSCND-BOLD.otf') }};
font-weight:bold; }
</style>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.