+
+
+
+```
+
+请注意,子模版并没有定义 `sidebar` block,所以系统使用了父模版中的值。父模版的 `{% block %}` 标签中的内容总是被用作备选内容(fallback)。
+
+您可以根据需要使用多级继承。使用继承的一个常用方式是类似下面的三级结构:
+
+* 创建一个 `base.html` 模版来控制您整个站点的主要视觉和体验。
+* 为您的站点的每一个“部分”创建一个`base_SECTIONNAME.html` 模版。 例如, `base_news.html`, `base_sports.html`。这些模版都继承自 `base.html` ,并且包含了每部分特有的样式和设计。
+* 为每一种页面类型创建独立的模版,例如新闻内容或者博客文章。这些模版继承了有关的部分模版(section template)。
+
+这种方式使代码得到最大程度的复用,并且使得添加内容到共享的内容区域更加简单,例如,部分范围内的导航。
+
+这里是使用继承的一些提示:
+
+* 如果你在模版中使用 [`{% extends %}`](builtins.html#std:templatetag-extends) 标签,它必须是模版中的第一个标签。其他的任何情况下,模版继承都将无法工作。
+
+* 在base模版中设置越多的 [`{% block %}`](builtins.html#std:templatetag-block) 标签越好。请记住,子模版不必定义全部父模版中的blocks,所以,你可以在大多数blocks中填充合理的默认内容,然后,只定义你需要的那一个。多一点钩子总比少一点好。
+
+* 如果你发现你自己在大量的模版中复制内容,那可能意味着你应该把内容移动到父模版中的一个 `{% block %}` 中。
+
+* If you need to get the content of the block from the parent template, the `{{ block.super }}` variable will do the trick. This is useful if you want to add to the contents of a parent block instead of completely overriding it. Data inserted using `{{ block.super }}` will not be automatically escaped (see the [next section](#automatic-html-escaping)), since it was already escaped, if necessary, in the parent template.
+
+* 为了更好的可读性,你也可以给你的 `{% endblock %}` 标签一个 _名字_ 。例如:
+
+ ```
+ {% block content %}
+ ...
+ {% endblock content %}
+
+ ```
+
+ 在大型模版中,这个方法帮你清楚的看到哪一个 `{% block %}` 标签被关闭了。
+
+最后,请注意您并不能在一个模版中定义多个相同名字的 [`block`](builtins.html#std:templatetag-block) 标签。这个限制的存在是因为block标签的作用是“双向”的。这个意思是,block标签不仅提供了一个坑去填,它还在 _父模版_中定义了填坑的内容。如果在一个模版中有两个名字一样的 [`block`](builtins.html#std:templatetag-block) 标签,模版的父模版将不知道使用哪个block的内容。
+
+## 自动HTML转义
+
+当从模版中生成HTML时,总会有这样一个风险:值可能会包含影响HTML最终呈现的字符。例如,思考这个模版片段:
+
+```
+Hello, {{ name }}
+
+```
+
+首先,它看起来像是一个无害的方式来显示用户的名字,但是设想一下,如果用户像下面这样输入他的名字,会发生什么:
+
+```
+
+
+```
+
+使用这个名字值,模版将会被渲染成这样:
+
+```
+Hello,
+
+```
+
+...这意味着,浏览器将会弹出一个Javascript警示框!
+
+类似的,如果名字包含一个 `'<'` 符号(比如下面这样),会发生什么呢?
+
+```
+username
+
+```
+
+这将会导致模版呗渲染成这样:
+
+```
+Hello, username
+
+```
+
+...进而这将导致网页的剩余部分都被加粗!
+
+显然,用户提交的数据都被应该被盲目的信任,并且被直接插入到你的网页中,因为一个怀有恶意的用户可能会使用这样的漏洞来做一些可能的坏事。这种类型的安全问题被叫做 [跨站脚本(Cross Site Scripting)](http://en.wikipedia.org/wiki/Cross-site_scripting) (XSS) 攻击。
+
+为避免这个问题,你有两个选择:
+
+* 第一, 你可以确保每一个不被信任的值都通过 [`escape`](builtins.html#std:templatefilter-escape) 过滤器(下面的文档中将提到)运行,它将把潜在的有害HTML字符转换成无害的。This was the default solution in Django for its first few years, but the problem is that it puts the onus on _you_, the developer / template author, to ensure you’re escaping everything. It’s easy to forget to escape data.
+* 第二,你可以利用Django的自动HTML转义。 本节描述其余部分描述的是自动转义是如何工作的
+
+By default in Django, every template automatically escapes the output of every variable tag. Specifically, these five characters are escaped:
+
+* `<`会转换为`<`
+* `>`会转换为`>`
+* `'` (单引号) 会转换为`'`
+* `"` (双引号)会转换为 `"`
+* `&` 会转换为 `&`
+
+我们要再次强调这是默认行为。如果你使用Django的模板系统,会处于保护之下。
+
+### 如果关闭它
+
+如果你不希望数据自动转义,在站点、模板或者变量级别,你可以使用几种方法来关闭它。
+
+然而你为什么想要关闭它呢?由于有时,模板变量含有一些你_打算_渲染成原始HTML的数据,你并不想转义这些内容。例如,你可能会在数据库中储存一些HTML代码,并且直接在模板中嵌入它们。或者,你可能使用Django的模板系统来生成_不是_HTML的文本 -- 比如邮件信息。
+
+#### 用于独立变量
+
+使用[`safe`](builtins.html#std:templatefilter-safe)过滤器来关闭独立变量上的自动转移:
+
+```
+This will be escaped: {{ data }}
+This will not be escaped: {{ data|safe }}
+
+```
+
+_safe_是_safe from further escaping_或者_can be safely interpreted as HTML_的缩写。
+在这个例子中,如果`data`含有`''`,输出会是:
+
+```
+This will be escaped:
+This will not be escaped:
+
+```
+
+#### 用于模板代码块
+
+要控制模板上的自动转移,将模板(或者模板中的特定区域)包裹在[`autoescape`](builtins.html#std:templatetag-autoescape)标签 中,像这样:
+
+```
+{% autoescape off %}
+ Hello {{ name }}
+{% endautoescape %}
+
+```
+
+[`autoescape`](builtins.html#std:templatetag-autoescape)标签接受`on` 或者 `off`作为它的参数。有时你可能想在自动转移关闭的情况下强制使用它。下面是一个模板的示例:
+
+```
+Auto-escaping is on by default. Hello {{ name }}
+
+{% autoescape off %}
+ This will not be auto-escaped: {{ data }}.
+
+ Nor this: {{ other_data }}
+ {% autoescape on %}
+ Auto-escaping applies again: {{ name }}
+ {% endautoescape %}
+{% endautoescape %}
+
+```
+
+自动转移标签作用于扩展了当前模板的模板,以及通过 [`include`](builtins.html#std:templatetag-include) 标签包含的模板,就像所有block标签那样。例如:
+
+base.html
+```
+{% autoescape off %}
+