我尝试过使用 @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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)