Added the JSONIFY_PRETTYPRINT_REGULAR config variable. This fixes #725
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parent 1c8c21a · Browse files · 4 files·+18 added−3 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+18 added−3 removed
- other:+18 added−3 removed
Provenance
- Commit
3d9055b- Tree
7069691- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
1c8c21a
4 files changed+18 added−3 removed
modified:docs/config.rst+6 added-1 removed
147 unmodified lines148 and output strings as-is and return149 unicode strings. ``jsonfiy`` will150 automatically encode it in ``utf-8``151 then for transport for instance.152+``JSONIFY_PRETTYPRINT_REGULAR`` If this is set to ``True`` (the default)153+ jsonify responses will be pretty printed154+ if they are not requested by an155+ XMLHttpRequest object (controlled by156+ the ``X-Requested-With`` header)157 ================================= =========================================158 159 .. admonition:: More on ``SERVER_NAME``160 35 unmodified lines196 .. versionadded:: 0.9197 ``PREFERRED_URL_SCHEME``198 199 .. versionadded:: 0.10195- ``JSON_AS_ASCII``200+ ``JSON_AS_ASCII``, ``JSONIFY_PRETTYPRINT_REGULAR``201 202 Configuring from Files203 ----------------------204 214 unmodified linesmodified:flask/app.py+2 added-1 removed
288 unmodified lines289 'SEND_FILE_MAX_AGE_DEFAULT': 12 * 60 * 60, # 12 hours290 'TRAP_BAD_REQUEST_ERRORS': False,291 'TRAP_HTTP_EXCEPTIONS': False,292 'PREFERRED_URL_SCHEME': 'http',293- 'JSON_AS_ASCII': True293+ 'JSON_AS_ASCII': True,294+ 'JSONIFY_PRETTYPRINT_REGULAR': True,295 })296 297 #: The rule object to use for URL rules created. This is used by298 #: :meth:`add_url_rule`. Defaults to :class:`werkzeug.routing.Rule`.1536 unmodified linesmodified:flask/json.py+9 added-1 removed
192 unmodified lines193 194 For security reasons only objects are supported toplevel. For more195 information about this, have a look at :ref:`json-security`.196 197+ This function's response will be pretty printed if it was not requested198+ with ``X-Requested-With: XMLHttpRequest`` to simplify debugging unless199+ the ``JSONIFY_PRETTYPRINT_REGULAR`` config parameter is set to false.200+201 .. versionadded:: 0.2202 """203+ indent = None204+ if current_app.config['JSONIFY_PRETTYPRINT_REGULAR'] \205+ and not request.is_xhr:206+ indent = 2207 return current_app.response_class(dumps(dict(*args, **kwargs),200- indent=None if request.is_xhr else 2),208+ indent=indent),209 mimetype='application/json')modified:CHANGES+1 added
60 unmodified lines61 for Python 3.3 port.62 - Changed how the teardown system is informed about exceptions. This is now63 more reliable in case something handles an exception halfway through64 the error handling process.65+- Added the ``JSONIFY_PRETTYPRINT_REGULAR`` configuration variable.66 67 Version 0.968 -----------69 365 unmodified lines