zoukankan      html  css  js  c++  java
  • flask基础知识

    关于flask框架的基础知识

    相关基础知识:定义路由,定义参数,获取参数,重定向

    简单易懂

    ---hello.py

    # -*- coding: utf-8 -*-
    # Flask hello world
    from flask import Flask, redirect
    from flask import render_template
    app = Flask(__name__)
    
    @app.route('/')
    def hello_flask():
        return('hello world!')
    
    @app.route('/aaa')
    def hello_aaa():
        return('hello aaaa!')
    
    ####目标  参数
    @app.route('/test')
    @app.route('/test/<name>')
    @app.route('/test/<name>/<sex>')
    def index(name=None, sex=None):
        return render_template('index.html', name=name, sex=sex)
    ####重定向
    @app.route('/redirect')
    def test():
        return redirect('/test/bob')
    
    ####路由详解
    @app.route('/long/<int:xx>/<float:num>/<path:str1>')
    def parse_test(xx, num, str1):
        xx = xx+1
        ####不能返回数字
        return (str(xx)) 
    
    if __name__ == '__main__':
        ####默认监听127.0.0.1:5000   关闭调试模式
        app.run(host='127.0.0.1',port=9999,debug=True)

    在cmd窗口运行改文件,然后就可以在浏览器里浏览上面定义的url,都是基础知识,再次不再赘述。

    flask是我个人比较喜欢的一款框架,有兴趣可以互相交流。

  • 相关阅读:
    Begin Again
    hadoop集群启动start-dfs.sh有节点datanode启动不了问题
    centos中python更新后yum不可用问题
    浏览器无法访问hdfs界面问题
    数据的统计分析与描述
    插值与拟合
    层次分析法
    四种规划-数学建模
    Hive深入使用
    Hadoop-Hive
  • 原文地址:https://www.cnblogs.com/shuangzikun/p/taotao_python_flask.html
Copyright © 2011-2022 走看看