引用了flask库,然后写了段小代码,希望能显示index里面内容,返回结果,通过本地127.0.0.1:5000 并不显示index里面的内容,请问是咋回事?
问题相关代码,请勿粘贴截图
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
- Serving Flask app 'server' (lazy loading)
- Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead. - Debug mode: off
- Running on http://127.0.0.1:5000 (Press CTRL+C to quit)
浏览器显示内容:
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文件里面的内容,并且能告知出错的原因。