源码: # -*- 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 abortfrom werkzeug.utils import redirectfrom jinja2 import Markup, escape from .app import Flask, Request, Responsefrom .config import Configfrom .helpers import url_for, flash, send_file, send_from_directory, \ get_flashed_messages, get_template_attribute, make_response, safe_join, \ stream_with_contextfrom .globals import current_app, g, request, session, _request_ctx_stack, \ _app_ctx_stackfrom .ctx import has_request_context, has_app_context, \ after_this_request, copy_current_request_contextfrom .blueprints import Blueprintfrom .templating import render_template, render_template_string # the signalsfrom .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.0from .sessions import SecureCookieSession as Sessionjson_available = True flask\__init__.py本模块顾名思义,主要是做了大量的初始化导入工作,方便后面的直接调用,其中最核心的一句
jsonify = json.jsonify, 在后面的json和接口开发中用得比较多,对json格式的接口交互,
相对 Python的原生json方法,我个人比较推荐用flask的jsonify方法,其直接返回的content-type就是json
原文地址:https://www.cnblogs.com/sea520/p/9995881.html
时间: 2024-10-04 18:40:35