@@ -324,6 +324,14 @@ the flexibility that other, stricter templating systems prevent.
324
324
Consequently, if you write random stuff inside of your template expressions,
325
325
you will get random Python errors when you execute the template.
326
326
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
+
327
335
328
336
### Cookies and secure cookies
329
337
@@ -708,13 +716,13 @@ Within `home.html`, you reference the `Entry` module rather than printing
708
716
the HTML directly:
709
717
710
718
{% for entry in entries %}
711
- {{ modules. Entry(entry) } }
719
+ {% module Entry(entry) % }
712
720
{% end %}
713
721
714
722
Within `entry.html`, you reference the `Entry` module with the
715
723
`show_comments` argument to show the expanded form of the entry:
716
724
717
- {{ modules. Entry(entry, show_comments=True) } }
725
+ {% module Entry(entry, show_comments=True) % }
718
726
719
727
Modules can include custom CSS and JavaScript functions by overriding
720
728
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
733
741
page, and JavaScript is always included just before the `</body>` tag
734
742
at the end of the page.
735
743
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
+
736
761
737
762
### Non-blocking, asynchronous requests
738
763
@@ -780,6 +805,26 @@ up after the client closes the connection (but see that method's docstring
780
805
for caveats).
781
806
782
807
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
+
783
828
### Third party authentication
784
829
785
830
Tornado's `auth` module implements the authentication and authorization
0 commit comments