gpt4 book ai didi

python - 如何在 python-flask 中添加自定义字体?

转载 作者:太空狗 更新时间:2023-10-30 02:29:25 30 4
gpt4 key购买 nike

我试过使用@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 渲染它时,它没有反射(reflect)字体。以下是我的 .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>

关于python - 如何在 python-flask 中添加自定义字体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32582644/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com