python3怎么建立一个简单的网页

代码如下,但运行不了
import web

urls = (
'/', 'index'
)

app = web.application(urls, globals())

class index:
def GET(self):
greeting = "hi world"
return greeting

if __name__== "__main__":
app.run()

安装第三方模块 flask(小辣椒)

编写脚本 my_index.py

from flask import Flask

app = Flask(__name__, static_url_path='')

@app.route('/')
def index():
    return app.send_static_file('index.html')

if __name__ == '__main__':
    app.debug = True  # 调试模式,修改文件会重新启动
    app.run(host='0.0.0.0', port=8000)  # 0.0.0.0 监听所有公网 IP

温馨提示:答案为网友推荐,仅供参考
相似回答