import flask
app = flask.Flask(name)
@app.route("/")
def index():
f=open("index.html","rb")
data=f.read()
f.close()
return data
app.run()
程序运行结果:
C:\Python39\python.exe F:/岁岁平安/server.py
浏览器显示内容:
Not Found
The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.
打开浏览器的时候,能显示本地index文件里面的内容,并且能告知出错的原因。
试试下面的代码:
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
if __name__ == '__main__':
app.run(debug = True)
记住,将index.html放在templates文件夹里面,里面在创建一个空的__init__.py文件,这个很重要,不然运行不成功。
你有加上斜杠嘛
你可以print 一下看看是否读取到了data