File tree Expand file tree Collapse file tree 9 files changed +23
-6
lines changed Expand file tree Collapse file tree 9 files changed +23
-6
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ response is sent.
3737 :caption: `` flaskr/ db.py``
3838
3939 import sqlite3
40+ from datetime import datetime
4041
4142 import click
4243 from flask import current_app, g
@@ -132,6 +133,11 @@ Add the Python functions that will run these SQL commands to the
132133 init_db()
133134 click.echo(' Initialized the database.' )
134135
136+
137+ sqlite3.register_converter(
138+ " timestamp" , lambda v : datetime.fromisoformat(v.decode())
139+ )
140+
135141:meth: `open_resource() <Flask.open_resource> ` opens a file relative to
136142the ``flaskr `` package, which is useful since you won't necessarily know
137143where that location is when deploying the application later. ``get_db ``
@@ -142,6 +148,10 @@ read from the file.
142148that calls the ``init_db `` function and shows a success message to the
143149user. You can read :doc: `/cli ` to learn more about writing commands.
144150
151+ The call to :func: `sqlite3.register_converter ` tells Python how to
152+ interpret timestamp values in the database. We convert the value to a
153+ :class: `datetime.datetime `.
154+
145155
146156Register with the Application
147157-----------------------------
Original file line number Diff line number Diff line change @@ -3,8 +3,8 @@ name = "flask-example-celery"
33version = " 1.0.0"
44description = " Example Flask application with Celery background tasks."
55readme = " README.md"
6- requires-python = " >=3.8 "
7- dependencies = [" flask>=2.2.2 " , " celery[redis]>=5.2.7 " ]
6+ classifiers = [ " Private :: Do Not Upload " ]
7+ dependencies = [" flask" , " celery[redis]" ]
88
99[build-system ]
1010requires = [" flit_core<4" ]
File renamed without changes.
Original file line number Diff line number Diff line change @@ -3,8 +3,9 @@ name = "js_example"
33version = " 1.1.0"
44description = " Demonstrates making AJAX requests to Flask."
55readme = " README.rst"
6- license = {file = " LICENSE.rst " }
6+ license = {file = " LICENSE.txt " }
77maintainers = [{
name =
" Pallets" ,
email =
" [email protected] " }]
8+ classifiers = [" Private :: Do Not Upload" ]
89dependencies = [" flask" ]
910
1011[project .urls ]
Original file line number Diff line number Diff line change 55@pytest .mark .parametrize (
66 ("path" , "template_name" ),
77 (
8- ("/" , "xhr .html" ),
8+ ("/" , "fetch .html" ),
99 ("/plain" , "xhr.html" ),
1010 ("/fetch" , "fetch.html" ),
1111 ("/jquery" , "jquery.html" ),
File renamed without changes.
Original file line number Diff line number Diff line change 11import sqlite3
2+ from datetime import datetime
23
34import click
45from flask import current_app
@@ -44,6 +45,9 @@ def init_db_command():
4445 click .echo ("Initialized the database." )
4546
4647
48+ sqlite3 .register_converter ("timestamp" , lambda v : datetime .fromisoformat (v .decode ()))
49+
50+
4751def init_app (app ):
4852 """Register database functions with the Flask app. This is called by
4953 the application factory.
Original file line number Diff line number Diff line change @@ -3,8 +3,9 @@ name = "flaskr"
33version = " 1.0.0"
44description = " The basic blog app built in the Flask tutorial."
55readme = " README.rst"
6- license = {text = " BSD-3-Clause " }
6+ license = {file = " LICENSE.txt " }
77maintainers = [{
name =
" Pallets" ,
email =
" [email protected] " }]
8+ classifiers = [" Private :: Do Not Upload" ]
89dependencies = [
910 " flask" ,
1011]
Original file line number Diff line number Diff line change @@ -547,7 +547,8 @@ def download_file(name):
547547 raises a 404 :exc:`~werkzeug.exceptions.NotFound` error.
548548
549549 :param directory: The directory that ``path`` must be located under,
550- relative to the current application's root path.
550+ relative to the current application's root path. This *must not*
551+ be a value provided by the client, otherwise it becomes insecure.
551552 :param path: The path to the file to send, relative to
552553 ``directory``.
553554 :param kwargs: Arguments to pass to :func:`send_file`.
You can’t perform that action at this time.
0 commit comments