zoukankan      html  css  js  c++  java
  • Flask框架返回值

    Flask中的HTTPResponse

    def index(): #视图函数
        return 'Hello World'  #直接return就是返回的字符串

    Flask中的Redirect,和django一样

    @qpp.route("/login")
    def index():
        return redirect("/login/")

    Flask 中的 render (render_template)

    from flask import Flask, render_template
    
    @app.route("/login")
    def login():
        return render_template("login.html")

    使用 render_template 返回渲染的模板,请在项目的主目录中加入一个目录 templates

    右击templates选择Mark Directory as --> Template Folder

     yes

     jinjia2 --> OK

    send_file

    send_file: 打开并返回文件内容 自动识别文件类型 并且加入 Content-type:文件类型,无法识别返回text

    @app.route("/mp4")
    def image():
        return send_file("1.mp4")

    jsonify

    返回标准格式的JSON字符串 在响应头中加入 Content-type:application/json

    @app.route()
    def get_jsom():
        dict = {"name":"value"}
        return jsonify(dict)
  • 相关阅读:
    Zookeeper服务器启动
    BeanFactoryPostProcessor
    ZK简介
    自定义标签解析
    高性能MySQL
    Redis原理
    ApplicationContext
    ThreadPoolExecutor
    NW.js构建PC收银端安装程序的指南
    NW.js安装原生node模块node-printer控制打印机
  • 原文地址:https://www.cnblogs.com/wanglan/p/10553286.html
Copyright © 2011-2022 走看看