Python中的Flask服务器破坏了外观



我试图在烧瓶中呈现我的网站,因为我在烧瓶中制作了后端。

我使用了以下两种代码:

def TestDir():
return render_template('Index/index.html')

def HomeDir():
return(open('Templates/Index/index.html').read())

但它显示了所有的故障:https://i.1nch.dev/cdn/0pPwq1kDY2Oc9CMM.gif

但在我的电脑上,它显示正常:https://i.1nch.dev/cdn/l3LnfmUzyad78Nl5.gif

您需要为css和js文件设置一个静态文件夹,除非在初始化Flask时覆盖它。

你的应用程序目录应该是这样的:

/app
- app_runner.py
/templates
/Index
- Index.html
/static
/css
- style.css

要访问html中的css文件,请使用以下内容:<link rel="stylesheet" type="text/css" href="{{ url_for('static',filename='css/style.css') }}">

最新更新