Skip to content

Commit 31e7b78

Browse files
committed
Update overview for new 2.0 features
1 parent 4e89201 commit 31e7b78

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

website/templates/overview.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
{% block headertitle %}<h1>overview</h1>{% end %}
66

77
{% block body %}
8-
{{ markdown("overview.txt", toc=True) }}
8+
{% raw markdown("overview.txt", toc=True) %}
99
{% end %}

website/templates/overview.txt

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,14 @@ the flexibility that other, stricter templating systems prevent.
324324
Consequently, if you write random stuff inside of your template expressions,
325325
you will get random Python errors when you execute the template.
326326

327+
All template output is escaped by default, using the
328+
`tornado.escape.xhtml_escape` function. This behavior can be changed globally
329+
by passing `autoescape=None` to the `Application` or `TemplateLoader`
330+
constructors, for a template file with the `{% autoescape None %}`
331+
directive, or for a single expression by replacing `{{ ... }}` with
332+
`{% raw ...%}`. Additionally, in each of these places the name of an
333+
alternative escaping function may be used instead of `None`.
334+
327335

328336
### Cookies and secure cookies
329337

@@ -708,13 +716,13 @@ Within `home.html`, you reference the `Entry` module rather than printing
708716
the HTML directly:
709717

710718
{% for entry in entries %}
711-
{{ modules.Entry(entry) }}
719+
{% module Entry(entry) %}
712720
{% end %}
713721

714722
Within `entry.html`, you reference the `Entry` module with the
715723
`show_comments` argument to show the expanded form of the entry:
716724

717-
{{ modules.Entry(entry, show_comments=True) }}
725+
{% module Entry(entry, show_comments=True) %}
718726

719727
Modules can include custom CSS and JavaScript functions by overriding
720728
the `embedded_css`, `embedded_javascript`, `javascript_files`, or
@@ -733,6 +741,23 @@ a module is used on a page. CSS is always included in the `<head>` of the
733741
page, and JavaScript is always included just before the `</body>` tag
734742
at the end of the page.
735743

744+
When additional Python code is not required, a template file itself may
745+
be used as a module. For example, the preceding example could be
746+
rewritten to put the following in `module-entry.html`:
747+
748+
{{ set_resources(embedded_css=".entry { margin-bottom: 1em; }") }}
749+
<!-- more template html... -->
750+
751+
This revised template module would be invoked with
752+
753+
{% module Template("module-entry.html", show_comments=True) %}
754+
755+
The `set_resources` function is only available in templates invoked via
756+
`{% module Template(...) %}`. Unlike the `{% include ... %}` directive,
757+
template modules have a distinct namespace from their containing template -
758+
they can only see the global template namespace and their own keyword
759+
arguments.
760+
736761

737762
### Non-blocking, asynchronous requests
738763

@@ -780,6 +805,26 @@ up after the client closes the connection (but see that method's docstring
780805
for caveats).
781806

782807

808+
### Asynchronous HTTP clients
809+
810+
Tornado includes two non-blocking HTTP client implementations:
811+
`SimpleAsyncHTTPClient` and `CurlAsyncHTTPClient`. The simple client
812+
has no external dependencies because it is implemented directly on top
813+
of Tornado's `IOLoop`. The Curl client requires that `libcurl` and
814+
`pycurl` be installed (and a recent version of each is highly
815+
recommended to avoid bugs in older version's asynchronous interfaces),
816+
but is more likely to be compatible with sites that exercise
817+
little-used parts of the HTTP specification.
818+
819+
Each of these clients is available in its own module
820+
(`tornado.simple_httpclient` and `tornado.curl_httpclient`), as well as
821+
via a configurable alias in `tornado.httpclient`. `SimpleAsyncHTTPClient`
822+
is the default, but to use a different implementation call the
823+
`AsyncHTTPClient.configure` method at startup:
824+
825+
AsyncHTTPClient.configure('tornado.curl_httpclient.CurlAsyncHTTPClient')
826+
827+
783828
### Third party authentication
784829

785830
Tornado's `auth` module implements the authentication and authorization

0 commit comments

Comments
 (0)