"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "docs/quickstart.rst" between
flask-1.1.1.tar.gz and flask-1.1.2.tar.gz

About: Flask is a lightweight Python WSGI web application framework.

quickstart.rst  (flask-1.1.1):quickstart.rst  (flask-1.1.2)
skipping to change at line 200 skipping to change at line 200
rules to a function. rules to a function.
Variable Rules Variable Rules
`````````````` ``````````````
You can add variable sections to a URL by marking sections with You can add variable sections to a URL by marking sections with
``<variable_name>``. Your function then receives the ``<variable_name>`` ``<variable_name>``. Your function then receives the ``<variable_name>``
as a keyword argument. Optionally, you can use a converter to specify the type as a keyword argument. Optionally, you can use a converter to specify the type
of the argument like ``<converter:variable_name>``. :: of the argument like ``<converter:variable_name>``. ::
from markupsafe import escape
@app.route('/user/<username>') @app.route('/user/<username>')
def show_user_profile(username): def show_user_profile(username):
# show the user profile for that user # show the user profile for that user
return 'User %s' % escape(username) return 'User %s' % escape(username)
@app.route('/post/<int:post_id>') @app.route('/post/<int:post_id>')
def show_post(post_id): def show_post(post_id):
# show the post with the given id, the id is an integer # show the post with the given id, the id is an integer
return 'Post %d' % post_id return 'Post %d' % post_id
skipping to change at line 280 skipping to change at line 282
``/myapplication`` instead of ``/``, :func:`~flask.url_for` properly ``/myapplication`` instead of ``/``, :func:`~flask.url_for` properly
handles that for you. handles that for you.
For example, here we use the :meth:`~flask.Flask.test_request_context` method For example, here we use the :meth:`~flask.Flask.test_request_context` method
to try out :func:`~flask.url_for`. :meth:`~flask.Flask.test_request_context` to try out :func:`~flask.url_for`. :meth:`~flask.Flask.test_request_context`
tells Flask to behave as though it's handling a request even while we use a tells Flask to behave as though it's handling a request even while we use a
Python shell. See :ref:`context-locals`. Python shell. See :ref:`context-locals`.
.. code-block:: python .. code-block:: python
from flask import Flask, escape, url_for from flask import Flask, url_for
from markupsafe import escape
app = Flask(__name__) app = Flask(__name__)
@app.route('/') @app.route('/')
def index(): def index():
return 'index' return 'index'
@app.route('/login') @app.route('/login')
def login(): def login():
return 'login' return 'login'
skipping to change at line 417 skipping to change at line 420
documentation. Basically template inheritance makes it possible to keep documentation. Basically template inheritance makes it possible to keep
certain elements on each page (like header, navigation and footer). certain elements on each page (like header, navigation and footer).
Automatic escaping is enabled, so if ``name`` contains HTML it will be escaped Automatic escaping is enabled, so if ``name`` contains HTML it will be escaped
automatically. If you can trust a variable and you know that it will be automatically. If you can trust a variable and you know that it will be
safe HTML (for example because it came from a module that converts wiki safe HTML (for example because it came from a module that converts wiki
markup to HTML) you can mark it as safe by using the markup to HTML) you can mark it as safe by using the
:class:`~jinja2.Markup` class or by using the ``|safe`` filter in the :class:`~jinja2.Markup` class or by using the ``|safe`` filter in the
template. Head over to the Jinja 2 documentation for more examples. template. Head over to the Jinja 2 documentation for more examples.
Here is a basic introduction to how the :class:`~jinja2.Markup` class works:: Here is a basic introduction to how the :class:`~markupsafe.Markup` class works: :
>>> from flask import Markup >>> from markupsafe import Markup
>>> Markup('<strong>Hello %s!</strong>') % '<blink>hacker</blink>' >>> Markup('<strong>Hello %s!</strong>') % '<blink>hacker</blink>'
Markup(u'<strong>Hello &lt;blink&gt;hacker&lt;/blink&gt;!</strong>') Markup(u'<strong>Hello &lt;blink&gt;hacker&lt;/blink&gt;!</strong>')
>>> Markup.escape('<blink>hacker</blink>') >>> Markup.escape('<blink>hacker</blink>')
Markup(u'&lt;blink&gt;hacker&lt;/blink&gt;') Markup(u'&lt;blink&gt;hacker&lt;/blink&gt;')
>>> Markup('<em>Marked up</em> &raquo; HTML').striptags() >>> Markup('<em>Marked up</em> &raquo; HTML').striptags()
u'Marked up \xbb HTML' u'Marked up \xbb HTML'
.. versionchanged:: 0.5 .. versionchanged:: 0.5
Autoescaping is no longer enabled for all templates. The following Autoescaping is no longer enabled for all templates. The following
skipping to change at line 761 skipping to change at line 764
In addition to the request object there is also a second object called In addition to the request object there is also a second object called
:class:`~flask.session` which allows you to store information specific to a :class:`~flask.session` which allows you to store information specific to a
user from one request to the next. This is implemented on top of cookies user from one request to the next. This is implemented on top of cookies
for you and signs the cookies cryptographically. What this means is that for you and signs the cookies cryptographically. What this means is that
the user could look at the contents of your cookie but not modify it, the user could look at the contents of your cookie but not modify it,
unless they know the secret key used for signing. unless they know the secret key used for signing.
In order to use sessions you have to set a secret key. Here is how In order to use sessions you have to set a secret key. Here is how
sessions work:: sessions work::
from flask import Flask, session, redirect, url_for, escape, request from flask import Flask, session, redirect, url_for, request
from markupsafe import escape
app = Flask(__name__) app = Flask(__name__)
# Set the secret key to some random bytes. Keep this really secret! # Set the secret key to some random bytes. Keep this really secret!
app.secret_key = b'_5#y2L"F4Q8z\n\xec]/' app.secret_key = b'_5#y2L"F4Q8z\n\xec]/'
@app.route('/') @app.route('/')
def index(): def index():
if 'username' in session: if 'username' in session:
return 'Logged in as %s' % escape(session['username']) return 'Logged in as %s' % escape(session['username'])
skipping to change at line 860 skipping to change at line 864
app.logger.debug('A value for debugging') app.logger.debug('A value for debugging')
app.logger.warning('A warning occurred (%d apples)', 42) app.logger.warning('A warning occurred (%d apples)', 42)
app.logger.error('An error occurred') app.logger.error('An error occurred')
The attached :attr:`~flask.Flask.logger` is a standard logging The attached :attr:`~flask.Flask.logger` is a standard logging
:class:`~logging.Logger`, so head over to the official :mod:`logging` :class:`~logging.Logger`, so head over to the official :mod:`logging`
docs for more information. docs for more information.
Read more on :ref:`application-errors`. Read more on :ref:`application-errors`.
Hooking in WSGI Middlewares Hooking in WSGI Middleware
--------------------------
To add WSGI middleware to your Flask application, wrap the application's
``wsgi_app`` attribute. For example, to apply Werkzeug's
:class:`~werkzeug.middlware.proxy_fix.ProxyFix` middleware for running
behind Nginx:
.. code-block:: python
If you want to add a WSGI middleware to your application you can wrap the from werkzeug.middleware.proxy_fix import ProxyFix
internal WSGI application. For example if you want to use one of the app.wsgi_app = ProxyFix(app.wsgi_app)
middlewares from the Werkzeug package to work around bugs in lighttpd, you
can do it like this::
from werkzeug.contrib.fixers import LighttpdCGIRootFix Wrapping ``app.wsgi_app`` instead of ``app`` means that ``app`` still
app.wsgi_app = LighttpdCGIRootFix(app.wsgi_app) points at your Flask application, not at the middleware, so you can
continue to use and configure ``app`` directly.
Using Flask Extensions Using Flask Extensions
---------------------- ----------------------
Extensions are packages that help you accomplish common tasks. For Extensions are packages that help you accomplish common tasks. For
example, Flask-SQLAlchemy provides SQLAlchemy support that makes it simple example, Flask-SQLAlchemy provides SQLAlchemy support that makes it simple
and easy to use with Flask. and easy to use with Flask.
For more on Flask extensions, have a look at :ref:`extensions`. For more on Flask extensions, have a look at :ref:`extensions`.
 End of changes. 8 change blocks. 
11 lines changed or deleted 22 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)