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
  • 相关阅读:
    Android 的 ramdisk.img、system.img、userdata.img 作用说明,以及UBoot 系统启动过程
    Android启动过程以及各个镜像的关系
    程序员如何利用空余时间挣零花钱?
    hcharts实现堆叠柱形图
    [慕课笔记] node+mongodb建站攻略
    【每周一图】蜂鸟
    [慕课笔记]Node入口文件分析和目录初始化
    [慕课笔记] node+mongodb建站攻略
    hcharts实现堆叠柱形图
    程序员常用的六大技术博客类
  • 原文地址:https://www.cnblogs.com/sea520/p/9995881.html
Copyright © 2011-2022 走看看