爬虫---11.flask

  • flask的基本使用

    • 环境安装:pip install flask
  • 简单服务端实例

                                from flask import Flask, render_template
                                from time import sleep
    
                                # flask的默认地址是 127.0.0.1:5000
                                # 在这个教程中 创建了一个模板文件夹 右键文件夹mark directory as  template folder
                                # render_template的功能是显示模板文件提示
    
                                # 实例化一个app
                                app = Flask(__name__)
    
                                # 创建试图函数&路由地址
                                @app.route('/bobo')
                                def index_1():
                                    sleep(2)
                                    return render_template('test.html')
    
                                @app.route('/jay')
                                def index_2():
                                    sleep(2)
                                    return render_template('test.html')
    
                                @app.route('/tom')
                                def index_3():
                                    sleep(2)
                                    return render_template('test.html')
    
                                if __name__ == "__main__":
                                    # debug = True 表示开启调试模式:服务器端代码被修改后按下保存键会自动重启服务
                                    app.run(debug=True)
原文地址:https://www.cnblogs.com/FGdeHB/p/15494094.html