forked from orbit-oss/flask
docs: `True, False and None`
This commit is contained in:
parent
6dbb015b43
commit
8284217593
19 changed files with 99 additions and 99 deletions
18
docs/api.rst
18
docs/api.rst
|
|
@ -115,7 +115,7 @@ Incoming Request Data
|
|||
|
||||
.. attribute:: is_xhr
|
||||
|
||||
`True` if the request was triggered via a JavaScript
|
||||
``True`` if the request was triggered via a JavaScript
|
||||
`XMLHttpRequest`. This only works with libraries that support the
|
||||
``X-Requested-With`` header and set it to `XMLHttpRequest`.
|
||||
Libraries that do that are prototype, jQuery and Mochikit and
|
||||
|
|
@ -178,14 +178,14 @@ To access the current session you can use the :class:`session` object:
|
|||
|
||||
.. attribute:: new
|
||||
|
||||
`True` if the session is new, `False` otherwise.
|
||||
``True`` if the session is new, ``False`` otherwise.
|
||||
|
||||
.. attribute:: modified
|
||||
|
||||
`True` if the session object detected a modification. Be advised
|
||||
``True`` if the session object detected a modification. Be advised
|
||||
that modifications on mutable structures are not picked up
|
||||
automatically, in that situation you have to explicitly set the
|
||||
attribute to `True` yourself. Here an example::
|
||||
attribute to ``True`` yourself. Here an example::
|
||||
|
||||
# this change is not picked up because a mutable object (here
|
||||
# a list) is changed.
|
||||
|
|
@ -195,9 +195,9 @@ To access the current session you can use the :class:`session` object:
|
|||
|
||||
.. attribute:: permanent
|
||||
|
||||
If set to `True` the session lives for
|
||||
If set to ``True`` the session lives for
|
||||
:attr:`~flask.Flask.permanent_session_lifetime` seconds. The
|
||||
default is 31 days. If set to `False` (which is the default) the
|
||||
default is 31 days. If set to ``False`` (which is the default) the
|
||||
session will be deleted when the user closes the browser.
|
||||
|
||||
|
||||
|
|
@ -279,7 +279,7 @@ thing, like it does for :class:`request` and :class:`session`.
|
|||
pattern for testing.
|
||||
|
||||
Additionally as of 0.10 you can use the :meth:`get` method to
|
||||
get an attribute or `None` (or the second argument) if it's not set.
|
||||
get an attribute or ``None`` (or the second argument) if it's not set.
|
||||
These two usages are now equivalent::
|
||||
|
||||
user = getattr(flask.g, 'user', None)
|
||||
|
|
@ -516,7 +516,7 @@ Signals
|
|||
|
||||
.. data:: signals_available
|
||||
|
||||
`True` if the signaling system is available. This is the case
|
||||
``True`` if the signaling system is available. This is the case
|
||||
when `blinker`_ is installed.
|
||||
|
||||
.. data:: template_rendered
|
||||
|
|
@ -782,7 +782,7 @@ Command Line Interface
|
|||
A special decorator that informs a click callback to be passed the
|
||||
script info object as first argument. This is normally not useful
|
||||
unless you implement very special commands like the run command which
|
||||
does not want the application to be loaded yet.
|
||||
does not want the application to be loaded yet.
|
||||
|
||||
.. autodata:: run_command
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ The following configuration values are used internally by Flask:
|
|||
``TESTING`` enable/disable testing mode
|
||||
``PROPAGATE_EXCEPTIONS`` explicitly enable or disable the
|
||||
propagation of exceptions. If not set or
|
||||
explicitly set to `None` this is
|
||||
explicitly set to ``None`` this is
|
||||
implicitly true if either `TESTING` or
|
||||
`DEBUG` is true.
|
||||
``PRESERVE_CONTEXT_ON_EXCEPTION`` By default if the application is in
|
||||
|
|
@ -80,20 +80,20 @@ The following configuration values are used internally by Flask:
|
|||
that is not set for ``'/'``.
|
||||
``SESSION_COOKIE_HTTPONLY`` controls if the cookie should be set
|
||||
with the httponly flag. Defaults to
|
||||
`True`.
|
||||
``True``.
|
||||
``SESSION_COOKIE_SECURE`` controls if the cookie should be set
|
||||
with the secure flag. Defaults to
|
||||
`False`.
|
||||
``False``.
|
||||
``PERMANENT_SESSION_LIFETIME`` the lifetime of a permanent session as
|
||||
:class:`datetime.timedelta` object.
|
||||
Starting with Flask 0.8 this can also be
|
||||
an integer representing seconds.
|
||||
``SESSION_REFRESH_EACH_REQUEST`` this flag controls how permanent
|
||||
sessions are refreshed. If set to `True`
|
||||
sessions are refreshed. If set to ``True``
|
||||
(which is the default) then the cookie
|
||||
is refreshed each request which
|
||||
automatically bumps the lifetime. If
|
||||
set to `False` a `set-cookie` header is
|
||||
set to ``False`` a `set-cookie` header is
|
||||
only sent if the session is modified.
|
||||
Non permanent sessions are not affected
|
||||
by this.
|
||||
|
|
|
|||
|
|
@ -176,7 +176,7 @@ request path up to the first slash::
|
|||
return app(environ, start_response)
|
||||
|
||||
The big difference between this and the subdomain one is that this one
|
||||
falls back to another application if the creator function returns `None`::
|
||||
falls back to another application if the creator function returns ``None``::
|
||||
|
||||
from myapplication import create_app, default_app, get_user_for_prefix
|
||||
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ operations: :meth:`~werkzeug.contrib.cache.BaseCache.get` and
|
|||
To get an item from the cache call
|
||||
:meth:`~werkzeug.contrib.cache.BaseCache.get` with a string as key name.
|
||||
If something is in the cache, it is returned. Otherwise that function
|
||||
will return `None`::
|
||||
will return ``None``::
|
||||
|
||||
rv = cache.get('my-item')
|
||||
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ your tarball::
|
|||
|
||||
Don't forget that even if you enlist them in your `MANIFEST.in` file, they
|
||||
won't be installed for you unless you set the `include_package_data`
|
||||
parameter of the `setup` function to `True`!
|
||||
parameter of the `setup` function to ``True``!
|
||||
|
||||
|
||||
Declaring Dependencies
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ Here is an example document (put this also into `app.py`, e.g.)::
|
|||
This example shows you how to define your schema (named structure), a
|
||||
validator for the maximum character length and uses a special MongoKit feature
|
||||
called `use_dot_notation`. Per default MongoKit behaves like a python
|
||||
dictionary but with `use_dot_notation` set to `True` you can use your
|
||||
dictionary but with `use_dot_notation` set to ``True`` you can use your
|
||||
documents like you use models in nearly any other ORM by using dots to
|
||||
separate between attributes.
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ often forgotten, but you don't have to do that by hand, there is a
|
|||
function for that that is used like a decorator (:func:`functools.wraps`).
|
||||
|
||||
This example assumes that the login page is called ``'login'`` and that
|
||||
the current user is stored as `g.user` and `None` if there is no-one
|
||||
the current user is stored as `g.user` and ``None`` if there is no-one
|
||||
logged in::
|
||||
|
||||
from functools import wraps
|
||||
|
|
@ -120,7 +120,7 @@ As you can see, if no template name is provided it will use the endpoint
|
|||
of the URL map with dots converted to slashes + ``'.html'``. Otherwise
|
||||
the provided template name is used. When the decorated function returns,
|
||||
the dictionary returned is passed to the template rendering function. If
|
||||
`None` is returned, an empty dictionary is assumed, if something else than
|
||||
``None`` is returned, an empty dictionary is assumed, if something else than
|
||||
a dictionary is returned we return it from the function unchanged. That
|
||||
way you can still use the redirect function or return simple strings.
|
||||
|
||||
|
|
@ -151,15 +151,15 @@ Endpoint Decorator
|
|||
------------------
|
||||
|
||||
When you want to use the werkzeug routing system for more flexibility you
|
||||
need to map the endpoint as defined in the :class:`~werkzeug.routing.Rule`
|
||||
to a view function. This is possible with this decorator. For example::
|
||||
need to map the endpoint as defined in the :class:`~werkzeug.routing.Rule`
|
||||
to a view function. This is possible with this decorator. For example::
|
||||
|
||||
from flask import Flask
|
||||
from werkzeug.routing import Rule
|
||||
|
||||
app = Flask(__name__)
|
||||
app.url_map.add(Rule('/', endpoint='index'))
|
||||
app = Flask(__name__)
|
||||
app.url_map.add(Rule('/', endpoint='index'))
|
||||
|
||||
@app.endpoint('index')
|
||||
def my_index():
|
||||
return "Hello world"
|
||||
@app.endpoint('index')
|
||||
def my_index():
|
||||
return "Hello world"
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ Things to remember:
|
|||
the data is submitted via the HTTP `POST` method and
|
||||
:attr:`~flask.request.args` if the data is submitted as `GET`.
|
||||
2. to validate the data, call the :func:`~wtforms.form.Form.validate`
|
||||
method which will return `True` if the data validates, `False`
|
||||
method which will return ``True`` if the data validates, ``False``
|
||||
otherwise.
|
||||
3. to access individual values from the form, access `form.<NAME>.data`.
|
||||
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ Comparisons:
|
|||
- against arbitrary types: ``==`` and ``!=``
|
||||
- against singletons with ``is`` and ``is not`` (eg: ``foo is not
|
||||
None``)
|
||||
- never compare something with `True` or `False` (for example never
|
||||
- never compare something with ``True`` or ``False`` (for example never
|
||||
do ``foo == False``, do ``not foo`` instead)
|
||||
|
||||
Negated containment checks:
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ every time the app context tears down. So what does this mean?
|
|||
Essentially the app context is created before the request comes in and is
|
||||
destroyed (torn down) whenever the request finishes. A teardown can
|
||||
happen because of two reasons: either everything went well (the error
|
||||
parameter will be `None`) or an exception happened in which case the error
|
||||
parameter will be ``None``) or an exception happened in which case the error
|
||||
is passed to the teardown function.
|
||||
|
||||
Curious about what these contexts mean? Have a look at the
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ redirect back to the `show_entries` page::
|
|||
return redirect(url_for('show_entries'))
|
||||
|
||||
Note that we check that the user is logged in here (the `logged_in` key is
|
||||
present in the session and `True`).
|
||||
present in the session and ``True``).
|
||||
|
||||
.. admonition:: Security Note
|
||||
|
||||
|
|
@ -61,7 +61,7 @@ Login and Logout
|
|||
These functions are used to sign the user in and out. Login checks the
|
||||
username and password against the ones from the configuration and sets the
|
||||
`logged_in` key in the session. If the user logged in successfully, that
|
||||
key is set to `True`, and the user is redirected back to the `show_entries`
|
||||
key is set to ``True``, and the user is redirected back to the `show_entries`
|
||||
page. In addition, a message is flashed that informs the user that he or
|
||||
she was logged in successfully. If an error occurred, the template is
|
||||
notified about that, and the user is asked again::
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue