mirror of https://github.com/pallets/flask.git
Merge remote-tracking branch 'origin/stable'
This commit is contained in:
commit
22c48a738b
|
@ -37,6 +37,7 @@ response is sent.
|
||||||
:caption: ``flaskr/db.py``
|
:caption: ``flaskr/db.py``
|
||||||
|
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
import click
|
import click
|
||||||
from flask import current_app, g
|
from flask import current_app, g
|
||||||
|
@ -132,6 +133,11 @@ Add the Python functions that will run these SQL commands to the
|
||||||
init_db()
|
init_db()
|
||||||
click.echo('Initialized the database.')
|
click.echo('Initialized the database.')
|
||||||
|
|
||||||
|
|
||||||
|
sqlite3.register_converter(
|
||||||
|
"timestamp", lambda v: datetime.fromisoformat(v.decode())
|
||||||
|
)
|
||||||
|
|
||||||
:meth:`open_resource() <Flask.open_resource>` opens a file relative to
|
:meth:`open_resource() <Flask.open_resource>` opens a file relative to
|
||||||
the ``flaskr`` package, which is useful since you won't necessarily know
|
the ``flaskr`` package, which is useful since you won't necessarily know
|
||||||
where that location is when deploying the application later. ``get_db``
|
where that location is when deploying the application later. ``get_db``
|
||||||
|
@ -142,6 +148,10 @@ read from the file.
|
||||||
that calls the ``init_db`` function and shows a success message to the
|
that calls the ``init_db`` function and shows a success message to the
|
||||||
user. You can read :doc:`/cli` to learn more about writing commands.
|
user. You can read :doc:`/cli` to learn more about writing commands.
|
||||||
|
|
||||||
|
The call to :func:`sqlite3.register_converter` tells Python how to
|
||||||
|
interpret timestamp values in the database. We convert the value to a
|
||||||
|
:class:`datetime.datetime`.
|
||||||
|
|
||||||
|
|
||||||
Register with the Application
|
Register with the Application
|
||||||
-----------------------------
|
-----------------------------
|
||||||
|
|
|
@ -3,8 +3,8 @@ name = "flask-example-celery"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
description = "Example Flask application with Celery background tasks."
|
description = "Example Flask application with Celery background tasks."
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.8"
|
classifiers = ["Private :: Do Not Upload"]
|
||||||
dependencies = ["flask>=2.2.2", "celery[redis]>=5.2.7"]
|
dependencies = ["flask", "celery[redis]"]
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["flit_core<4"]
|
requires = ["flit_core<4"]
|
||||||
|
|
|
@ -3,8 +3,9 @@ name = "js_example"
|
||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
description = "Demonstrates making AJAX requests to Flask."
|
description = "Demonstrates making AJAX requests to Flask."
|
||||||
readme = "README.rst"
|
readme = "README.rst"
|
||||||
license = {file = "LICENSE.rst"}
|
license = {file = "LICENSE.txt"}
|
||||||
maintainers = [{name = "Pallets", email = "contact@palletsprojects.com"}]
|
maintainers = [{name = "Pallets", email = "contact@palletsprojects.com"}]
|
||||||
|
classifiers = ["Private :: Do Not Upload"]
|
||||||
dependencies = ["flask"]
|
dependencies = ["flask"]
|
||||||
|
|
||||||
[project.urls]
|
[project.urls]
|
||||||
|
|
|
@ -5,7 +5,7 @@ from flask import template_rendered
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("path", "template_name"),
|
("path", "template_name"),
|
||||||
(
|
(
|
||||||
("/", "xhr.html"),
|
("/", "fetch.html"),
|
||||||
("/plain", "xhr.html"),
|
("/plain", "xhr.html"),
|
||||||
("/fetch", "fetch.html"),
|
("/fetch", "fetch.html"),
|
||||||
("/jquery", "jquery.html"),
|
("/jquery", "jquery.html"),
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
import click
|
import click
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
|
@ -44,6 +45,9 @@ def init_db_command():
|
||||||
click.echo("Initialized the database.")
|
click.echo("Initialized the database.")
|
||||||
|
|
||||||
|
|
||||||
|
sqlite3.register_converter("timestamp", lambda v: datetime.fromisoformat(v.decode()))
|
||||||
|
|
||||||
|
|
||||||
def init_app(app):
|
def init_app(app):
|
||||||
"""Register database functions with the Flask app. This is called by
|
"""Register database functions with the Flask app. This is called by
|
||||||
the application factory.
|
the application factory.
|
||||||
|
|
|
@ -3,8 +3,9 @@ name = "flaskr"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
description = "The basic blog app built in the Flask tutorial."
|
description = "The basic blog app built in the Flask tutorial."
|
||||||
readme = "README.rst"
|
readme = "README.rst"
|
||||||
license = {text = "BSD-3-Clause"}
|
license = {file = "LICENSE.txt"}
|
||||||
maintainers = [{name = "Pallets", email = "contact@palletsprojects.com"}]
|
maintainers = [{name = "Pallets", email = "contact@palletsprojects.com"}]
|
||||||
|
classifiers = ["Private :: Do Not Upload"]
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"flask",
|
"flask",
|
||||||
]
|
]
|
||||||
|
|
|
@ -547,7 +547,8 @@ def send_from_directory(
|
||||||
raises a 404 :exc:`~werkzeug.exceptions.NotFound` error.
|
raises a 404 :exc:`~werkzeug.exceptions.NotFound` error.
|
||||||
|
|
||||||
:param directory: The directory that ``path`` must be located under,
|
:param directory: The directory that ``path`` must be located under,
|
||||||
relative to the current application's root path.
|
relative to the current application's root path. This *must not*
|
||||||
|
be a value provided by the client, otherwise it becomes insecure.
|
||||||
:param path: The path to the file to send, relative to
|
:param path: The path to the file to send, relative to
|
||||||
``directory``.
|
``directory``.
|
||||||
:param kwargs: Arguments to pass to :func:`send_file`.
|
:param kwargs: Arguments to pass to :func:`send_file`.
|
||||||
|
|
Loading…
Reference in New Issue