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是我个人比较喜欢的一款框架,有兴趣可以互相交流。

  • 相关阅读:
    gdb调试core文件
    设计模式之工厂模式
    设计模式之简单工厂模式
    正确理解python的装饰器
    深入理解MVC架构
    django的模板系统过滤器笔记
    python net-snmp 的使用
    用django写个CMS系统
    django的CMS系统(内容管理系统)
    RESTful 的通俗解释
  • 原文地址:https://www.cnblogs.com/shuangzikun/p/taotao_python_flask.html
Copyright © 2011-2022 走看看