如何在python-flask中添加自定义字体? [英] How to add custom font in python-flask?

查看:45
本文介绍了如何在python-flask中添加自定义字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用@fontface css样式,但是未呈现字体.还有另一种使用python/flask做到这一点的方法吗?

I have tried using @fontface css style, but the font doesn't get rendered. Is there another way of doing this using 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代码:

The above is my HTML template. Unfortunately, when I render it using Flask, it doesn't reflect the font. The following is my .py code:

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)

推荐答案

非常感谢您的所有帮助.所有建议的组合终于奏效了.

Thanks a lot for all your help.. A combination of all the suggestions finally worked.

在此处发布解决方案:

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-flask中添加自定义字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆