zoukankan      html  css  js  c++  java
  • Flask源码阅读-第二篇(flask\__init__.py)

    源码:

    # -*- coding: utf-8 -*-
    """
    flask
    ~~~~~

    A microframework based on Werkzeug. It's extensively documented
    and follows best practice patterns.

    :copyright: © 2010 by the Pallets team.
    :license: BSD, see LICENSE for more details.
    """

    __version__ = '1.0.2'

    # utilities we import from Werkzeug and Jinja2 that are unused
    # in the module but are exported as public interface.
    from werkzeug.exceptions import abort
    from werkzeug.utils import redirect
    from jinja2 import Markup, escape

    from .app import Flask, Request, Response
    from .config import Config
    from .helpers import url_for, flash, send_file, send_from_directory,
    get_flashed_messages, get_template_attribute, make_response, safe_join,
    stream_with_context
    from .globals import current_app, g, request, session, _request_ctx_stack,
    _app_ctx_stack
    from .ctx import has_request_context, has_app_context,
    after_this_request, copy_current_request_context
    from .blueprints import Blueprint
    from .templating import render_template, render_template_string

    # the signals
    from .signals import signals_available, template_rendered, request_started,
    request_finished, got_request_exception, request_tearing_down,
    appcontext_tearing_down, appcontext_pushed,
    appcontext_popped, message_flashed, before_render_template

    # We're not exposing the actual json module but a convenient wrapper around
    # it.
    from . import json

    # This was the only thing that Flask used to export at one point and it had
    # a more generic name.
    jsonify = json.jsonify

    # backwards compat, goes away in 1.0
    from .sessions import SecureCookieSession as Session
    json_available = True


    flask\__init__.py本模块顾名思义,主要是做了大量的初始化导入工作,方便后面的直接调用,其中最核心的一句
    jsonify = json.jsonify, 在后面的json和接口开发中用得比较多,对json格式的接口交互,
    相对 Python的原生json方法,我个人比较推荐用flask的jsonify方法,其直接返回的content-type就是json
  • 相关阅读:
    c语言 数组名是常量指针
    c语言 动态数组
    c语言 指针的值
    c语言 &取地址运算符的理解
    c语言 指针与地址的区别
    c语言 指针与数组
    linux cheese摄像机工具在window电脑上显示
    C#实现简单的 Ping 的功能,用于测试网络是否已经联通
    c# 扫描局域网IP列表的几种方法
    c# 遍历局域网计算机(电脑)获取IP和计算机名称
  • 原文地址:https://www.cnblogs.com/sea520/p/9995881.html
Copyright © 2011-2022 走看看