Bur*_*lid 20
您的代码不使用Flask提供文件,它只是读取文件并将其发送到浏览器 - 这就是URL不起作用的原因.
您需要在方法中呈现文件.
首先在与templates文件相同的目录中创建一个文件夹,.py然后将html文件移动到此文件夹中.创建另一个名为的文件夹static,并将样式表放在该文件夹中.
你应该有
/flaskwp1.py
/templates
webcode.html
/static
webcodestyle.css
Run Code Online (Sandbox Code Playgroud)
然后,调整您的代码:
from flask import Flask, render_template
app = Flask('flaskwp1')
# webcode = open('webcode.html').read() - not needed
@app.route('/')
def webprint():
return render_template('webcode.html')
if __name__ == '__main__':
app.run(host = '0.0.0.0', port = 3000)
Run Code Online (Sandbox Code Playgroud)
编辑webcode.html:
<link rel="stylesheet"
type="text/css"
href="/static/webcodestyle.css"/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21234 次 |
| 最近记录: |