提交 8cc3f838 编写于 作者: W wizardforcel

format

上级 e67c6422
......@@ -49,13 +49,15 @@ class MyForm(forms.Form):
_class _`RegexValidator`([_regex=None_, _message=None_, _code=None_, _inverse_match=None_, _flags=0_])[[source]](../_modules/django/core/validators.html#RegexValidator)
<table class="docutils field-list" frame="void" rules="none"><colgroup><col class="field-name"><col class="field-body"></colgroup><tbody valign="top"><tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body">* **regex** – 如果不是`None`则覆写 [`regex`](#django.core.validators.RegexValidator.regex "django.core.validators.RegexValidator.regex")。可以是一个正则表达式字符串,或者预编译的正则表达式对象。
Parameters:
* **regex** – 如果不是`None`则覆写 [`regex`](#django.core.validators.RegexValidator.regex "django.core.validators.RegexValidator.regex")。可以是一个正则表达式字符串,或者预编译的正则表达式对象。
* **message** – 如果不是`None`,则覆写 [`message`](#django.core.validators.RegexValidator.message "django.core.validators.RegexValidator.message")
* **code** – 如果不是`None`,则覆写[`code`](#django.core.validators.RegexValidator.code "django.core.validators.RegexValidator.code")
* **inverse_match** – 如果不是`None`,则覆写[`inverse_match`](#django.core.validators.RegexValidator.inverse_match "django.core.validators.RegexValidator.inverse_match")
* **flags** – 如果不是`None`,则覆写 [`flags`](#django.core.validators.RegexValidator.flags "django.core.validators.RegexValidator.flags")。这种情况下,[`regex`](#django.core.validators.RegexValidator.regex "django.core.validators.RegexValidator.regex") ,必须是正则表达式字符串,否则抛出[`TypeError`](https://docs.python.org/3/library/exceptions.html#TypeError) 异常。
</td></tr></tbody></table>
`regex`
......@@ -85,11 +87,13 @@ New in Django 1.7\.
_class _`EmailValidator`([_message=None_, _code=None_, _whitelist=None_])[[source]](../_modules/django/core/validators.html#EmailValidator)
<table class="docutils field-list" frame="void" rules="none"><colgroup><col class="field-name"><col class="field-body"></colgroup><tbody valign="top"><tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body">* **message** – 如果不是 `None`,则覆写[`message`](#django.core.validators.EmailValidator.message "django.core.validators.EmailValidator.message")
Parameters:
* **message** – 如果不是 `None`,则覆写[`message`](#django.core.validators.EmailValidator.message "django.core.validators.EmailValidator.message")
* **code** – 如果不是 `None`,则覆写[`code`](#django.core.validators.EmailValidator.code "django.core.validators.EmailValidator.code")
* **whitelist** – 如果不是`None`,则覆写 [`whitelist`](#django.core.validators.EmailValidator.whitelist "django.core.validators.EmailValidator.whitelist")
</td></tr></tbody></table>
`message`
......
......@@ -926,16 +926,16 @@ New in Django 1.8\.
使用参数来发送`EmailMultiAlternatives`。可以覆盖来自定义邮件如何发送给用户。
<table class="docutils field-list" frame="void" rules="none"><colgroup><col class="field-name"><col class="field-body"></colgroup><tbody valign="top"><tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body">* **subject_template_name** – the template for the subject.
Parameters:
* **subject_template_name** – the template for the subject.
* **email_template_name** – the template for the email body.
* **context** – context passed to the `subject_template`, `email_template`,
and `html_email_template` (if it is not `None`).
* **context** – context passed to the `subject_template`, `email_template`, and `html_email_template` (if it is not `None`).
* **from_email** – the sender’s email.
* **to_email** – the email of the requester.
* **html_email_template_name** – the template for the HTML body;
defaults to `None`, in which case a plain text email is sent.
* **html_email_template_name** – the template for the HTML body; defaults to `None`, in which case a plain text email is sent.
</td></tr></tbody></table>
通常,&nbsp;`save()` 位于`context`中,并带有&nbsp;[`password_reset()`](#django.contrib.auth.views.password_reset ) 向它的email上下文传递的一些变量。
......
# 消息框架
# 消息框架
在网页应用中,你经常需要在处理完表单或其它类型的用户输入后,显示一个通知消息(也叫做“flash message”)给用户。
......@@ -61,7 +61,7 @@ _class_ `storage.base.``BaseStorage`
可以直接从`django.contrib.messages` 导入的内建级别有:
<colgroup><col width="11%"> <col width="89%"></colgroup>
| Constant | Purpose |
| --- | --- |
| `DEBUG` | Development-related messages that will be ignored (or removed) in a production deployment |
......@@ -76,7 +76,7 @@ _class_ `storage.base.``BaseStorage`
消息的标签是一个字符串,表示消息的级别以及在视图中添加的其它标签(参见下文[添加额外的消息标签](#adding-extra-message-tags))。标签存储在字符串中并通过空格分隔。通常情况下,消息的标签用于作为CSS 类来根据消息的类型定制消息的风格。默认情况下,每个级别具有一个标签,为其级别的字符串常量的小写:
<colgroup><col width="56%"> <col width="44%"></colgroup>
| Level Constant | Tag |
| --- | --- |
| `DEBUG` | `debug` |
......@@ -204,7 +204,7 @@ def my_view(request):
在创建自定义消息级别时,应小心避免重载现有级别。内置级别的值为:
<colgroup><col width="74%"> <col width="26%"></colgroup>
| Level Constant | Value |
| --- | --- |
| `DEBUG` | 10 |
......@@ -357,4 +357,3 @@ New in Django 1.7.
* [SESSION_COOKIE_DOMAIN](../settings.html#std:setting-SESSION_COOKIE_DOMAIN)
* [SESSION_COOKIE_SECURE](../settings.html#std:setting-SESSION_COOKIE_SECURE)
* [SESSION_COOKIE_HTTPONLY](../settings.html#std:setting-SESSION_COOKIE_HTTPONLY)
......@@ -134,7 +134,7 @@ serializers.deserialize("xml", data, ignorenonexistent=True)
Django支持多种序列化格式,其中一些格式要求您安装第三方Python模块:
<colgroup><col width="14%"> <col width="86%"></colgroup>
| Identifier | Information |
| --- | --- |
| `xml` | Serializes to and from a simple XML dialect. |
......@@ -439,4 +439,3 @@ natural_key.dependencies = ['example_app.person']
```
此定义确保所有`Person`对象在任何`Book`对象之前序列化。反过来,在`Person``Book`序列化之后,引用`Book`的任何对象将被序列化。
......@@ -30,12 +30,14 @@ Django 提供了[_一系列的内建信号_](../ref/signals.html),允许用户
`Signal.``connect`(_receiver_[, _sender=None_, _weak=True_, _dispatch_uid=None_])
<table class="docutils field-list" frame="void" rules="none"><colgroup><col class="field-name"><col class="field-body"></colgroup><tbody valign="top"><tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body">* **receiver** – 和这个信号连接的回调函数。详见[_接收器函数_](#receiver-functions)
Parameters:
* **receiver** – 和这个信号连接的回调函数。详见[_接收器函数_](#receiver-functions)
* **sender** – 指定一个特定的发送器,来从它那里接受信号。详见[_连接由指定发送器发送的信号_](#connecting-to-specific-signals)
* **weak** – DJango通常以弱引用储存信号处理器。这就是说,如果你的接收器是个局部变量,可能会被垃圾回收。当你调用信号的`connect()`方法是,传递&nbsp;`weak=False`来防止这样做。
* **dispatch_uid** – 一个信号接收器的唯一标识符,以防信号多次发送。详见[_防止重复的信号_](#preventing-duplicate-signals)
</td></tr></tbody></table>
让我们来看一看它如何通过注册在每次在HTTP请求结束时调用的信号来工作。我们将会连接到[`request_finished`](../ref/signals.html#django.core.signals.request_finished "django.core.signals.request_finished") 信号。
......@@ -70,7 +72,9 @@ request_finished.connect(my_callback)
`receiver`(_signal_)
<table class="docutils field-list" frame="void" rules="none"><colgroup><col class="field-name"><col class="field-body"></colgroup><tbody valign="top"><tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body">**signal** – A signal or a list of signals to connect a function to.</td></tr></tbody></table>
Parameters:
**signal** – A signal or a list of signals to connect a function to.
下面是使用装饰器连接的方法:
......
此差异已折叠。
......@@ -142,7 +142,7 @@ DATABASES = {
### 版本支持
### 版本支持
Django 支持MySQL 5.5 和更高版本。
......@@ -179,7 +179,8 @@ _mysql_exceptions.OperationalError: (
<colgroup><col class="label"><col></colgroup>
| | |
| --- | --- |
| [[1]](#id4) | Unless this was changed by the packager of your MySQL package. We’ve had reports that the Windows Community Server installer sets up InnoDB as the default storage engine, for example. |
......@@ -351,37 +352,37 @@ default-character-set = utf8
* 在表创建之后, 执行 `ALTER TABLE`语句来转换表为一个新的储存引擎 (例如 InnoDB):
```
ALTER TABLE <tablename> ENGINE=INNODB;
```
如果你有很多表,这会很繁琐。
* 另一个选择是对于MySQLdb使用`init_command`选项在你创建表之前。
```
'OPTIONS': {
'init_command': 'SET storage_engine=INNODB',
}
```
这设置默认的储存引擎在连接数据库之上。创建了表之后,您应该删除这个选项,因为它增加了一个只需要在每个表创建数据库连接时的查询。
......@@ -536,9 +537,9 @@ Python的SQLite封装有一个默认的超时时间值决定了在超时之前
* 增加默认超时时间值通过设置`timeout`数据库选项:
```
'OPTIONS': {
......@@ -546,12 +547,12 @@ Python的SQLite封装有一个默认的超时时间值决定了在超时之前
'timeout': 20,
# ...
}
```
这只会使SQLite等一段时间才会抛出“database is locked”错误;它不会真的做一些事情去解决他们。
......@@ -814,6 +815,3 @@ The Oracle后端存储 `TextFields`像`NCLOB` 列.。通常使用LOB列时,Ora
* [ADSDB](http://code.google.com/p/adsdb-django/)
Django版本和ORM特性被支持通过这些非官方的后端相当大的变化。查询这些非官方的后端有关的特定功能,以及任何支持的查询,应该针对每个第三方项目提供的支持项目。
......@@ -97,183 +97,6 @@ Deprecated since version 1.8: `context_data` 以前只接受一个 [`Context`](t
`SimpleTemplateResponse.__init__`(_template_, _context=None_, _content_type=None_, _status=None_, _charset=None_, _using=None_)[[source]](../_modules/django/template/response.html#SimpleTemplateResponse.__init__)
使用给定的模板、上下文、Content-Type、HTTP 状态和字符集初始化一个[`SimpleTemplateResponse`](#django.template.response.SimpleTemplateResponse "django.template.response.SimpleTemplateResponse") 对象。
`template`
一个与后端有关的模板对象(例如[`get_template()`](../topics/templates.html#django.template.loader.get_template "django.template.loader.get_template") 返回的对象)、模板的名称或者一个模板名称列表。
Deprecated since version 1.8: `template` 以前只接受一个[`Template`](templates/api.html#django.template.Template "django.template.Template")
`context`
一个[`dict`](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.4)"),包含要添加到模板上下文中的值。它默认是一个空的字典。
Deprecated since version 1.8: `context` 以前只接受一个[`Context`](templates/api.html#django.template.Context "django.template.Context")
`content_type`
HTTP `Content-Type` 头部包含的值,包含MIME 类型和字符集的编码。 如果指定`content_type`,则使用它的值。 否则,使用[`DEFAULT_CONTENT_TYPE`](settings.html#std:setting-DEFAULT_CONTENT_TYPE)
`status`
响应的HTTP 状态码。
`charset`
响应编码使用的字符集。 如果没有给出则从`content_type`中提取,如果提取不成功则使用 [`DEFAULT_CHARSET`](settings.html#std:setting-DEFAULT_CHARSET) 设置。
`using`
加载模板使用的模板引擎的[`名称`](settings.html#std:setting-TEMPLATES-NAME)
Changed in Django 1.8:
添加`charset``using` 参数。
`SimpleTemplateResponse.resolve_context`(_context_)[[source]](../_modules/django/template/response.html#SimpleTemplateResponse.resolve_context)
预处理上下文数据(context data),这个上下文数据将会被用来渲染的模版。接受包含上下文数据的一个[`dict`](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.4)")。默认返回同一个[`dict`](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.4)")
若要自定义上下文,请覆盖这个方法。
Changed in Django 1.8:
`resolve_context` 返回一个[`dict`](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.4)")。它以前返回一个[`Context`](templates/api.html#django.template.Context "django.template.Context")
Deprecated since version 1.8: `resolve_context` 不再接受[`Context`](templates/api.html#django.template.Context "django.template.Context")
`SimpleTemplateResponse.resolve_template`(_template_)[[source]](../_modules/django/template/response.html#SimpleTemplateResponse.resolve_template)
解析渲染用到的模板实例。接收一个与后端有关的模板对象(例如[`get_template()`](../topics/templates.html#django.template.loader.get_template "django.template.loader.get_template") 返回的对象)、模板的名称或者一个模板名称列表。
返回将被渲染的模板对象。
若要自定义模板的加载,请覆盖这个方法。
Changed in Django 1.8:
`resolve_template` 返回一个与后端有关的模板对象。它以前返回一个[`Template`](templates/api.html#django.template.Template "django.template.Template")
Deprecated since version 1.8: `resolve_template` 不再接受一个 [`Template`](templates/api.html#django.template.Template "django.template.Template")
`SimpleTemplateResponse.add_post_render_callback`()[[source]](../_modules/django/template/response.html#SimpleTemplateResponse.add_post_render_callback)
添加一个渲染之后调用的回调函数。这个钩子可以用来延迟某些特定的处理操作(例如缓存)到渲染之后。
如果[`SimpleTemplateResponse`](#django.template.response.SimpleTemplateResponse "django.template.response.SimpleTemplateResponse") 已经渲染,那么回调函数将立即执行。
调用时,将只传递给回调函数一个参数 —— 渲染后的 [`SimpleTemplateResponse`](#django.template.response.SimpleTemplateResponse "django.template.response.SimpleTemplateResponse") 实例。
如果回调函数返回非`None` 值,它将用作响应并替换原始的响应对象(以及传递给下一个渲染之后的回调函数,以此类推)。
`SimpleTemplateResponse.render`()[[source]](../_modules/django/template/response.html#SimpleTemplateResponse.render)
设置`response.content`[`SimpleTemplateResponse.rendered_content`](#django.template.response.SimpleTemplateResponse.rendered_content "django.template.response.SimpleTemplateResponse.rendered_content") 的结果,执行所有渲染之后的回调函数,最后返回生成的响应对象。
`render()` 只在第一次调用它时其作用。以后的调用将返回第一次调用的结果。
## TemplateResponse 对象
_class_ `TemplateResponse`[[source]](../_modules/django/template/response.html#TemplateResponse)
`TemplateResponse`[`SimpleTemplateResponse`](#django.template.response.SimpleTemplateResponse "django.template.response.SimpleTemplateResponse") 的子类,而且能知道当前的[`HttpRequest`](request-response.html#django.http.HttpRequest "django.http.HttpRequest")
### 方法
`TemplateResponse.__init__`(_request_, _template_, _context=None_, _content_type=None_, _status=None_, _current_app=None_, _charset=None_, _using=None_)[[source]](../_modules/django/template/response.html#TemplateResponse.__init__)
使用给定的模板、上下文、Content-Type、HTTP 状态和字符集实例化一个[`TemplateResponse`](#django.template.response.TemplateResponse "django.template.response.TemplateResponse") 对象。
......
......@@ -279,7 +279,7 @@ In this syntax, each value gets interpreted as a literal string, and there’s n
for循环设置了一系列在循环中可用的变量:
<colgroup><col width="36%"> <col width="64%"></colgroup>
| Variable | Description |
| --- | --- |
| `forloop.counter` | The current iteration of the loop (1-indexed) |
......@@ -703,7 +703,7 @@ New in Django 1.8:
可以使用零个,一个,两个或三个参数使用`{% lorem %}` 。这些参数是:
<colgroup><col width="15%"> <col width="85%"></colgroup>
| Argument | Description |
| --- | --- |
| `count` | A number (or variable) containing the number of paragraphs or words to generate (default is 1). |
......@@ -935,7 +935,7 @@ Note that if you use `{% ssi %}`, you’ll need to define `'allowed_include_root
参数指定要输出哪个模板位:
<colgroup><col width="72%"> <col width="28%"></colgroup>
| Argument | Outputs |
| --- | --- |
| `openblock` | `{%` |
......@@ -1212,7 +1212,6 @@ The previous more verbose format is still supported: `{% with business.employees
可用的格式字符串:
<colgroup><col width="12%"> <col width="31%"> <col width="57%"></colgroup>
| Format character | Description | Example output |
| --- | --- | --- |
| a | `'a.m.'` or `'p.m.'` (Note that this is slightly different than PHP’s output, because this includes periods to match Associated Press style.) | `'a.m.'` |
......@@ -1469,7 +1468,7 @@ the output would be the string `"09/01/2008"` (the `"SHORT_DATE_FORMAT"` format
当不使用参数时,将浮点数舍入到小数点后一位,但前提是要显示小数部分。例如:
<colgroup><col width="26%"> <col width="57%"> <col width="17%"></colgroup>
| `value` | Template | Output |
| --- | --- | --- |
| `34.23234` | `{{ value&#124;floatformat }}` | `34.2` |
......@@ -1478,7 +1477,7 @@ the output would be the string `"09/01/2008"` (the `"SHORT_DATE_FORMAT"` format
如果与数字整数参数一起使用,`floatformat`将数字四舍五入为小数位数。例如:
<colgroup><col width="24%"> <col width="57%"> <col width="20%"></colgroup>
| `value` | Template | Output |
| --- | --- | --- |
| `34.23234` | `{{ value&#124;floatformat:3 }}` | `34.232` |
......@@ -1487,7 +1486,7 @@ the output would be the string `"09/01/2008"` (the `"SHORT_DATE_FORMAT"` format
特别有用的是传递0(零)作为参数,它将使float浮动到最接近的整数。
<colgroup><col width="22%"> <col width="59%"> <col width="19%"></colgroup>
| `value` | Template | Output |
| --- | --- | --- |
| `34.23234` | `{{ value&#124;floatformat:"0" }}` | `34` |
......@@ -1496,7 +1495,7 @@ the output would be the string `"09/01/2008"` (the `"SHORT_DATE_FORMAT"` format
如果传递给`floatformat`的参数为负,则它会将一个数字四舍五入到小数点后的位置,但前提是要显示一个小数部分。例如:
<colgroup><col width="22%"> <col width="59%"> <col width="19%"></colgroup>
| `value` | Template | Output |
| --- | --- | --- |
| `34.23234` | `{{ value&#124;floatformat:"-3" }}` | `34.232` |
......@@ -2195,7 +2194,7 @@ slug
```
<colgroup><col width="13%"> <col width="29%"> <col width="57%"></colgroup>
| Value | Argument | Outputs |
| --- | --- | --- |
| `True` |   | `yes` |
......@@ -2310,4 +2309,4 @@ You should prefer the [`static`](#std:templatetag-static) template tag, but if y
通过将值存储在数据属性中,如果我们想在JavaScript上下文中使用它,我们确保它适当地转义。
{% endraw %}
\ No newline at end of file
{% endraw %}
......@@ -37,7 +37,7 @@ _class_ `ModelForm`
每个模型字段有一个对应的默认表单字段。比如,模型中的`CharField` 表现成表单中的`CharField`。模型中的`ManyToManyField` 字段会表现成`MultipleChoiceField` 字段。下面是一个完整的列表:
<colgroup><col width="41%"> <col width="59%"></colgroup>
| Model field | Form field |
| --- | --- |
| [`AutoField`](../../ref/models/fields.html#django.db.models.AutoField "django.db.models.AutoField") | Not represented in the form |
......@@ -1003,4 +1003,3 @@ def manage_books(request, author_id):
### 指定要在内联表单中使用的窗口小部件
`inlineformset_factory`使用`modelformset_factory`并将其大部分参数传递给`modelformset_factory`。这意味着您可以使用`widgets`参数,将其传递到`modelformset_factory`。请参阅上面的[指定要在窗体中使用的窗口小部件](#specifying-widgets-to-use-in-the-form-with-widgets)的窗口小部件。
......@@ -981,7 +981,7 @@ Changed in Django 1.7:
Django本身使用这个信号来重置各种数据:
<colgroup><col width="43%"> <col width="57%"></colgroup>
| Overridden settings | Data reset |
| --- | --- |
| USE_TZ, TIME_ZONE | Databases timezone |
......
......@@ -2225,7 +2225,7 @@ url(r'^reset/done/$', auth_views.password_reset_complete, name='password_reset_c
[`AdminSite`](#django.contrib.admin.AdminSite "django.contrib.admin.AdminSite") 提供以下命名URL:
<colgroup><col width="30%"> <col width="29%"> <col width="41%"></colgroup>
| Page | URL name | Parameters |
| --- | --- | --- |
| Index | `index` |   |
......@@ -2238,7 +2238,7 @@ url(r'^reset/done/$', auth_views.password_reset_complete, name='password_reset_c
每个[`ModelAdmin`](#django.contrib.admin.ModelAdmin "django.contrib.admin.ModelAdmin") 实例还将提供额外的命名URL:
<colgroup><col width="27%"> <col width="57%"> <col width="16%"></colgroup>
| Page | URL name | Parameters |
| --- | --- | --- |
| Changelist | `{{ app_label }}_{{ model_name }}_changelist` |   |
......@@ -2280,4 +2280,3 @@ url(r'^reset/done/$', auth_views.password_reset_complete, name='password_reset_c
```
在上面的例子中Action 将匹配上文所述的[`ModelAdmin`](#django.contrib.admin.ModelAdmin "django.contrib.admin.ModelAdmin") 实例的URL 名称的最后部分。`opts` 变量可以是任何具有`app_label``model_name` 属性的对象,通常由Admin 视图为当前的模型提供。
......@@ -8,6 +8,8 @@
## 下载 ##
+ [在线阅读](https://www.gitbook.com/book/wizardforcel/django-chinese-docs-18/details)
+ [PDF下载](https://www.gitbook.com/download/pdf/book/wizardforcel/django-chinese-docs-18)
+ [EPUB下载](https://www.gitbook.com/download/epub/book/wizardforcel/django-chinese-docs-18)
+ [MOBI下载](https://www.gitbook.com/download/mobi/book/wizardforcel/django-chinese-docs-18)
+ [代码仓库](https://github.com/wizardforcel/django-chinese-docs-18)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册