Merge branch '1.0.x'

This commit is contained in:
David Lord 2019-06-23 16:56:42 -07:00
commit 1351d0a565
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
84 changed files with 1029 additions and 1439 deletions

View file

@ -60,7 +60,7 @@ Factories & Extensions
It's preferable to create your extensions and app factories so that the
extension object does not initially get bound to the application.
Using `Flask-SQLAlchemy <http://flask-sqlalchemy.pocoo.org/>`_,
Using `Flask-SQLAlchemy <https://flask-sqlalchemy.palletsprojects.com/>`_,
as an example, you should not do something along those lines::
def create_app(config_filename):

View file

@ -97,3 +97,29 @@ An example template might be this:
<p>What you were looking for is just not there.
<p><a href="{{ url_for('index') }}">go somewhere nice</a>
{% endblock %}
Returning API errors as JSON
----------------------------
When using Flask for web APIs, you can use the same techniques as above
to return JSON responses to API errors. :func:`~flask.abort` is called
with a ``description`` parameter. The :meth:`~flask.errorhandler` will
use that as the JSON error message, and set the status code to 404.
.. code-block:: python
from flask import abort, jsonify
@app.errorhandler(404)
def resource_not_found(e):
return jsonify(error=str(e)), 404
@app.route("/cheese")
def get_one_cheese():
resource = get_resource()
if resource is None:
abort(404, description="Resource not found")
return jsonify(resource)

View file

@ -27,7 +27,7 @@ to add a script statement to the bottom of your ``<body>`` to load jQuery:
url_for('static', filename='jquery.js') }}"></script>
Another method is using Google's `AJAX Libraries API
<https://developers.google.com/speed/libraries/devguide>`_ to load jQuery:
<https://developers.google.com/speed/libraries/>`_ to load jQuery:
.. sourcecode:: html

View file

@ -22,7 +22,7 @@ if you want to get started quickly.
You can download `Flask-SQLAlchemy`_ from `PyPI
<https://pypi.org/project/Flask-SQLAlchemy/>`_.
.. _Flask-SQLAlchemy: http://flask-sqlalchemy.pocoo.org/
.. _Flask-SQLAlchemy: https://flask-sqlalchemy.palletsprojects.com/
Declarative