python爬虫项目学习(数据可视化)

数据可视化

flask框架补充

#路由解析,通过用户访问的路径,匹配相应的函数
# @app.route('/')
# def hello_world():  # put application's code here
#     return 'Hello World!'

#通过访问路径,获取用户的字符串参数或整形参数,此外还有float类型
# @app.route('/user/<name>')
# def hello(name):
#     return 'Hello %s'%name
#
# @app.route('/user/<int:id>')
# def hello1(id):
#     return 'Hello the %d '%id
#路由路径不能重复,用户通过唯一的路径访问特定的函数

#返回给用户渲染后的网页文件
# @app.route('/')
# def index():
#     return render_template("index.html")

#向页面传递一个变量
# @app.route('/')
# def index2():
#     time=datetime.date.today()  #普通变量
#     name=["校长","班主任","数学老师"]
#     task={"任务":"打扫卫生","时间":"仨小时"}
#     return render_template("index.html",var=time,list=name,task=task)

对应的HTML语言——index.html
**<body>
    今天是{{ var }} <br/>
    今天值班的有: <br/>
    {% for data in list %} <!--用大括号和百分号括起来的是控制结构,还有if结构-->
        <li>{{ data }}</li>
    {% endfor %}<br/>
    任务:<br/>
        <table border="1">
            {% for key,value in task.items() %}<!--[(key,value),(key,value),(key,value)]-->
                <tr>
                <td>{{ key }}</td>
                <td>{{ value }}</td>
                </tr>
            {% endfor %}<br/>
        </table>
</body>**



#表单提交
# @app.route('/test/register')
# def register():
#     return render_template("test/register.html")

#接受表单提交的路由,需要指定method为post
# @app.route('/result',methods=['POST','GET'])
# def result():
#     if request.method=='POST':
#         result=request.form
#     return render_template("test/result.html",result=result)

对应的HTML语言——register.html与result.html
<body>

<form action="{{ url_for('result')}}" method="post">    #这里的action传入地址更加安全,避免页面源码泄露目录路径
    <p>姓名:<input type="text" name="姓名"></p>
    <p>年龄:<input type="text" name="年龄"></p>
    <p>性别:<input type="text" name="性别"></p>
    <p>地址:<input type="text" name="地址"></p>
    <p>姓名:<input type="submit" value="提交"></p>
</form>

<body>
        <table border="1">
            {% for key,value in result.items() %}<!--[(key,value),(key,value),(key,value)]-->
                <tr>
                <th>{{ key }}</th>
                <td>{{ value }}</td>
                </tr>
            {% endfor %}<br/>
        </table>
</body>

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值