Skip to content
Myr

Merge branch '2.0.x'

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Lord · committed by David Lord · parents 44bc286, 303a1e6 · Browse files · 10 files+50 added−50 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

10 files+50 added−50 removed

  • other:+50 added−50 removed

10 files+50 added−50 removed

modified:docs/patterns/sqlite3.rst+3 added-3 removed
111 unmodified lines
112113Here is how you can use it::114115 for user in query_db('select * from users'):116 print user['username'], 'has the id', user['user_id']116 print(user['username'], 'has the id', user['user_id'])117118Or if you just want a single result::119120 user = query_db('select * from users where username = ?',121 [the_username], one=True)122 if user is None:123 print 'No such user'123 print('No such user')124 else:125 print the_username, 'has the id', user['user_id']125 print(the_username, 'has the id', user['user_id'])126127To pass variable parts to the SQL statement, use a question mark in the128statement and pass in the arguments as a list. Never directly add them to129the SQL statement with string formatting because this makes it possible
22 unmodified lines
modified:docs/tutorial/deploy.rst+3 added-3 removed
86 unmodified lines
87You can use the following command to output a random secret key:8889.. code-block:: none9091 $ python -c 'import os; print(os.urandom(16))'91 $ python -c 'import secrets; print(secrets.token_hex())'9293 b'_5#y2L"F4Q8z\n\xec]/'93 '192b9bdd22ab9ed4d12e236c78afcb9a393ec15f71bbf5dc987d54727823bcbf'9495Create the ``config.py`` file in the instance folder, which the factory96will read from if it exists. Copy the generated value into it.9798.. code-block:: python99 :caption: ``venv/var/flaskr-instance/config.py``100101 SECRET_KEY = b'_5#y2L"F4Q8z\n\xec]/'101 SECRET_KEY = '192b9bdd22ab9ed4d12e236c78afcb9a393ec15f71bbf5dc987d54727823bcbf'102103You can also set any other necessary configuration here, although104``SECRET_KEY`` is the only one needed for Flaskr.105
34 unmodified lines
modified:docs/config.rst+4 added-4 removed
36 unmodified lines
37method::3839 app.config.update(40 TESTING=True,41 SECRET_KEY=b'_5#y2L"F4Q8z\n\xec]/'41 SECRET_KEY='192b9bdd22ab9ed4d12e236c78afcb9a393ec15f71bbf5dc987d54727823bcbf'42 )434445Environment and Debug Features
133 unmodified lines
179 and can be used for any other security related needs by extensions or your180 application. It should be a long random ``bytes`` or ``str``. For181 example, copy the output of this to your config::182183 $ python -c 'import os; print(os.urandom(16))'184 b'_5#y2L"F4Q8z\n\xec]/'183 $ python -c 'import secrets; print(secrets.token_hex())'184 '192b9bdd22ab9ed4d12e236c78afcb9a393ec15f71bbf5dc987d54727823bcbf'185186 **Do not reveal the secret key when posting questions or committing code.**187188 Default: ``None``
278 unmodified lines
467468Here is an example of a configuration file::469470 # Example configuration471 SECRET_KEY = b'_5#y2L"F4Q8z\n\xec]/'471 SECRET_KEY = '192b9bdd22ab9ed4d12e236c78afcb9a393ec15f71bbf5dc987d54727823bcbf'472473Make sure to load the configuration very early on, so that extensions have474the ability to access the configuration when starting up. There are other475methods on the config object as well to load from individual files. For a
293 unmodified lines
modified:docs/quickstart.rst+2 added-2 removed
845 unmodified lines
846 ways to generate pretty random data based on a cryptographic random847 generator. Use the following command to quickly generate a value for848 :attr:`Flask.secret_key` (or :data:`SECRET_KEY`)::849850 $ python -c 'import os; print(os.urandom(16))'851 b'_5#y2L"F4Q8z\n\xec]/'850 $ python -c 'import secrets; print(secrets.token_hex())'851 '192b9bdd22ab9ed4d12e236c78afcb9a393ec15f71bbf5dc987d54727823bcbf'852853A note on cookie-based sessions: Flask will take the values you put into the854session object and serialize them into a cookie. If you are finding some855values do not persist across requests, cookies are indeed enabled, and you are
83 unmodified lines
modified:docs/signals.rst+1 added-1 removed
175 unmodified lines
176 from flask import template_rendered177178 @template_rendered.connect_via(app)179 def when_template_rendered(sender, template, context, **extra):180 print f'Template {template.name} is rendered with {context}'180 print(f'Template {template.name} is rendered with {context}')181182Core Signals183------------184
4 unmodified lines
modified:requirements/dev.txt+20 added-20 removed
1#2# This file is autogenerated by pip-compile with python 3.92# This file is autogenerated by pip-compile with python 3.103# To update, run:4#5# pip-compile requirements/dev.in6#
8 unmodified lines
15backports.entry-points-selectable==1.1.016 # via virtualenv17blinker==1.418 # via -r requirements/tests.in19certifi==2021.5.3019certifi==2021.10.820 # via requests21cffi==1.14.621cffi==1.15.022 # via cryptography23cfgv==3.3.124 # via pre-commit25charset-normalizer==2.0.625charset-normalizer==2.0.726 # via requests27click==8.0.127click==8.0.328 # via pip-tools29cryptography==35.0.030 # via -r requirements/typing.in31distlib==0.3.3
1 unmodified line
33docutils==0.1634 # via35 # sphinx36 # sphinx-tabs37filelock==3.2.037filelock==3.3.238 # via39 # tox40 # virtualenv41greenlet==1.1.242 # via -r requirements/tests.in43identify==2.2.1543identify==2.3.344 # via pre-commit45idna==3.245idna==3.346 # via requests47imagesize==1.2.048 # via sphinx49iniconfig==1.1.150 # via pytest51jinja2==3.0.151jinja2==3.0.252 # via sphinx53markupsafe==2.0.154 # via jinja255mypy==0.910
1 unmodified line
57mypy-extensions==0.4.358 # via mypy59nodeenv==1.6.060 # via pre-commit61packaging==21.061packaging==21.262 # via63 # pallets-sphinx-themes64 # pytest65 # sphinx66 # tox67pallets-sphinx-themes==2.0.168 # via -r requirements/docs.in69pep517==0.11.069pep517==0.12.070 # via pip-tools71pip-tools==6.3.071pip-tools==6.4.072 # via -r requirements/dev.in73platformdirs==2.4.074 # via virtualenv75pluggy==1.0.0
15 unmodified lines
91pyparsing==2.4.792 # via packaging93pytest==6.2.594 # via -r requirements/tests.in95python-dotenv==0.19.095python-dotenv==0.19.196 # via -r requirements/tests.in97pytz==2021.197pytz==2021.398 # via babel99pyyaml==5.4.199pyyaml==6.0100 # via pre-commit101requests==2.26.0102 # via sphinx103six==1.16.0
32 unmodified lines
136 # mypy137 # pre-commit138 # pytest139 # tox140tomli==1.2.1140tomli==1.2.2141 # via pep517142tox==3.24.4143 # via -r requirements/dev.in144types-contextvars==0.1.4144types-contextvars==2.4.0145 # via -r requirements/typing.in146types-dataclasses==0.1.7146types-dataclasses==0.6.1147 # via -r requirements/typing.in148types-setuptools==57.4.0148types-setuptools==57.4.2149 # via -r requirements/typing.in150typing-extensions==3.10.0.2151 # via mypy152urllib3==1.26.7153 # via requests154virtualenv==20.8.1154virtualenv==20.10.0155 # via156 # pre-commit157 # tox158wheel==0.37.0
5 unmodified lines
modified:requirements/docs.txt+7 added-7 removed
1#2# This file is autogenerated by pip-compile with python 3.92# This file is autogenerated by pip-compile with python 3.103# To update, run:4#5# pip-compile requirements/docs.in6#7alabaster==0.7.128 # via sphinx9babel==2.9.110 # via sphinx11certifi==2021.5.3011certifi==2021.10.812 # via requests13charset-normalizer==2.0.613charset-normalizer==2.0.714 # via requests15docutils==0.1616 # via17 # sphinx18 # sphinx-tabs19idna==3.219idna==3.320 # via requests21imagesize==1.2.022 # via sphinx23jinja2==3.0.123jinja2==3.0.224 # via sphinx25markupsafe==2.0.126 # via jinja227packaging==21.027packaging==21.228 # via29 # pallets-sphinx-themes30 # sphinx31pallets-sphinx-themes==2.0.1
3 unmodified lines
35 # sphinx36 # sphinx-tabs37pyparsing==2.4.738 # via packaging39pytz==2021.139pytz==2021.340 # via babel41requests==2.26.042 # via sphinx43snowballstemmer==2.1.0
31 unmodified lines
modified:requirements/tests.txt+3 added-3 removed
1#2# This file is autogenerated by pip-compile with python 3.92# This file is autogenerated by pip-compile with python 3.103# To update, run:4#5# pip-compile requirements/tests.in6#
6 unmodified lines
13greenlet==1.1.214 # via -r requirements/tests.in15iniconfig==1.1.116 # via pytest17packaging==21.017packaging==21.218 # via pytest19pluggy==1.0.020 # via pytest21py==1.10.0
1 unmodified line
23pyparsing==2.4.724 # via packaging25pytest==6.2.526 # via -r requirements/tests.in27python-dotenv==0.19.027python-dotenv==0.19.128 # via -r requirements/tests.in29toml==0.10.230 # via pytest
modified:requirements/typing.txt+5 added-5 removed
1#2# This file is autogenerated by pip-compile with python 3.92# This file is autogenerated by pip-compile with python 3.103# To update, run:4#5# pip-compile requirements/typing.in6#7cffi==1.14.67cffi==1.15.08 # via cryptography9cryptography==35.0.010 # via -r requirements/typing.in11mypy==0.910
3 unmodified lines
15pycparser==2.2016 # via cffi17toml==0.10.218 # via mypy19types-contextvars==0.1.419types-contextvars==2.4.020 # via -r requirements/typing.in21types-dataclasses==0.1.721types-dataclasses==0.6.122 # via -r requirements/typing.in23types-setuptools==57.4.023types-setuptools==57.4.224 # via -r requirements/typing.in25typing-extensions==3.10.0.226 # via mypy
modified:.pre-commit-config.yaml+2 added-2 removed
12 unmodified lines
13 name: Reorder Python imports (src, tests)14 files: "^(?!examples/)"15 args: ["--application-directories", "src"]16 - repo: https://github.com/psf/black17 rev: 21.9b017 rev: 21.10b018 hooks:19 - id: black20 - repo: https://github.com/PyCQA/flake821 rev: 3.9.221 rev: 4.0.122 hooks:23 - id: flake824 additional_dependencies:25 - flake8-bugbear
7 unmodified lines