帮忙翻译:P COUNTER OUThold是什么意思思?

counter display是什么意思_百度知道
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。
counter display是什么意思
counter display计数器;柜面式;柜台显示例句1.Counter Display is available in hundreds of styles, in-stock to suit all of yourneeds of display.计数器显示有几百种款式,库存适合您的所有需求显示。2.There are many styles, sizes or merchant price points of display counter.有许多风格,大小或商家的价格点显示计数器。
采纳率:85%
来自团队:
ping' sound.-----------------------------------如有疑问欢迎追问counter display计数器显示双语对照词典结果:counter display[英][ˈkauntəplei][美][ˈkaʊntɚ dɪˈsple]柜头陈列样品; 以上结果来自金山词霸例句:1.This should open a sample clock counter display with a one second ' dis&#712
本回答被提问者和网友采纳
为您推荐:
其他类似问题
您可能关注的内容
display的相关知识
换一换
回答问题,赢新手礼包English原文
最近翻译记录
Chapter 4: The Django Template System
-------------------------------------
第四章 Django模板系统
-------------------------------------
In the previous chapter, you may have noticed something peculiar in how we returned
the text in our example views. Namely, the HTML was hard-coded directly in our
Python code.
在之前的章节中,你可能觉得例子中视图返回文本有点不妥。即是, HTML 是直接写在 Python 代码中的。
This arrangement leads to several problems:
这种做法会导致这些问题:
Any change to the design of the page requires a change to the Python code. The
design of a site tends to change far more frequently than the underlying Python
code, so it would be convenient if the the design could change without needing
to modify the Python code.
要做任何设计上的更改就必须改写 Python 代码。网站的设计风格的更变一般来说会比更改后台的
Ptyhon 代码来得频繁,因此如果能够更改设计而不用更改 Python 变得尤为方便。
Writing Python code and designing HTML are two different disciplines, and most
professional Web development environments split these responsibilities between
separate people (or even separate departments). Designers and HTML/CSS coders
shouldnt have to edit Python code t they should deal with
Python 代码编写和 HTML 设计是两项不同的工作,大多数专业的网站开发环境都将他们分配给不同的人员(甚至不同部门)来完成。设计人员和 HTML/CSS 编写人员都不应该通过编辑 Python 代码来完成自己的工作;他们应该处理的是 HTML。
Similarly, its most efficient if programmers can work on Python code and
designers can work on templates at the same time, rather than one person waiting
for the other to finish editing a single file that contains both Python and
同理,程序员编写 Python 代码和设计人员制作模板同时进行的工作方式效率是最高的,远胜于让一个人等待另一个人完成对某个既包含 Python 又包含 HTML 的文件的编辑工作。
For these reasons, its much cleaner and more maintainable to separate the design of
the page from the Python code itself. We can do this with Djangos *template system*
, which we discuss in this chapter.
基于这些原因,将页面的设计和Python的代码分离开会更干净简洁更容易维护。我们可以使用
Django的 *模板系统* (Template System)来实现这种模式,这就是本章要具体讨论的问题。
Template System Basics
``````````````````````
模板系统基本知识
``````````````````````
A Django template is a string of text that is intended to separate the presentation
of a document from its data. A template defines placeholders and various bits of
basic logic (i.e., template tags) that regulate how the document should be
displayed. Usually, templates are used for producing HTML, but Django templates are
equally capable of generating any text-based format.
模板系统基本知识
``````````````````````
Lets dive in with a simple example template. This template describes an HTML page
that thanks a person for placing an order with a company. Think of it as a form
让我们深入分析一个简单的例子模板。该模板描述了一个向某个与公司签单人员致谢 HTML 页面。可将其视为一个格式信函:
This template is basic HTML with some variables and template tags thrown in. Lets
step through it:
该模板是一段添加了些许变量和模板标签的基础 HTML 。让我们逐句过一遍:
Any text surrounded by a pair of braces (e.g., ``{{ person_name }}`` ) is a
*variable* . This means insert the value of the variable with the given name.
How do we specify the values of the variables? Well get to that in a moment.
用两个大括号括起来的文字(例如 ``{{ person_name }}`` )是 *变量(variable)* 。这意味着将按照给定的名字插入变量的值。如何指定变量的值呢?稍后就会说明。
Any text thats surrounded by curly braces and percent signs (e.g., ``{% if
ordered_warranty %}`` ) is a *template tag* . The definition of a tag is quite
broad: a tag just tells the template system to do something.
被大括号和百分号包围的文本(例如 ``{% if ordered_warranty %}`` )是 *模板标签(template tag)* 。标签(tag)定义比较明确,即:仅通知模板系统完成某些工作。
This example template contains two tags: the ``{% for item in item_list %}`` tag
(a ``for`` tag) and the ``{% if ordered_warranty %}`` tag (an ``if`` tag).
这个示例模板包含两个标签(tag): ``{% for item in item_list %}`` 标签(一个 ``for`` 标签)
和 ``{% if ordered_warranty %}`` 标签 (一个 ``if`` 标签)。
A ``for`` tag acts as a simple loop construct, letting you loop over each item
in a sequence. An ``if`` tag, as you may expect, acts as a logical if statement.
In this particular case, the tag checks whether the value of the
``ordered_warranty`` variable evaluates to ``True`` . If it does, the template
system will display everything between the ``{% if ordered_warranty %}`` and
``{% endif %}`` . If not, the template system wont display it. The template
system also supports ``{% else %}`` and other various logic statements.
``for`` 标签用于构建简单的循环,允许你遍历循环中的每一项。 ``if`` 标签,正如你所料,是用来执行逻辑判断的。在这个例子中标签检测 ``ordered_warranty`` 变量值是否为 ``True`` 。
如果是,模板系统将显示 ``{% if ordered_warranty %}`` 与 ``{% endif %}`` 之间的所有内容。
如果不是模板系统不会显示它。它当然也支持 ``{% else %}`` 以及其他多种逻辑判断方式。
Finally, the second paragraph of this template has an example of a *filter* ,
with which you can alter the display of a variable. In this example, ``{{
ship_date|date:&F j, Y& }}`` , were passing the ``ship_date`` variable to the
``date`` filter, giving the ``date`` filter the argument ``&F j, Y&`` . The
``date`` filter formats dates in a given format, as specified by that argument.
Filters are attached using a pipe character (``|`` ), as a reference to Unix
最后,这个模板的第二段落有一个 *filter* 过滤器的例子,它能让你用来转换变量的输出,
在这个例子中, ``{{ship_date|date:&F j, Y& }}`` 将变量 ``ship_date`` 用 ``date``
过滤器来转换,转换的参数是 ``&F j, Y&`` . ``date`` 过滤器根据指定的参数进行格式输出。过滤器是用管道字符( ``|`` )来调用的,就和Unix管道一样.
Each Django template has access to several built-in tags and filters, many of which
are discussed in the sections that follow. Appendix F contains the full list of tags
and filters, and its a good idea to familiarize yourself with that list so you know
whats possible. Its also possible to create your own filters and tags, which we
cover in Chapter 10.
Django 模板含有很多内置的tags和filters,我们将陆续进行学习.
附录F列出了很多的tags和filters的列表,熟悉这些列表对你来说是个好建议.
学习完第十章,你就明白怎么去创建自己的filters和tags了.
Using the Template System
`````````````````````````
如何使用模板系统
`````````````````````````
To use the template system in Python code, just follow these two steps:
想要在Python代码中使用模板系统,只需遵循下面两个步骤:
Create a ``Template`` object by providing the raw template code as a string.
Django also offers a way to create ``Template`` objects by designating the path
to a template fi well examine that in a bit.
可以用原始的模板代码字符串创建一个 ``Template`` 对象,
Django同样支持用指定模板文件路径的方式来创建 ``Template`` 对象;
Call the ``render()`` method of the ``Template`` object with a given set of
variables (i.e., the context). This returns a fully rendered template as a
string, with all of the variables and block tags evaluated according to the
调用 ``Template`` 对象的 ``render()`` 方法并提供给他变量(i.e., 内容).
它将返回一个完整的模板字符串内容,包含了所有标签块与变量解析后的内容.
The following sections describe each step in more detail.
以下部分逐步的详细介绍
Creating Template Objects
'''''''''''''''''''''''''
创建模板对象
''''''''''''
The easiest way to create a ``Template`` object is to instantiate it directly. The
``Template`` class lives in the ``django.template`` module, and the constructor
takes one argument, the raw template code. Lets dip into the Python interactive
interpreter to see how this works in code.
创建一个 ``Template`` 对象最简单的方法就是直接实例化它。 ``Template`` 类就在
``django.template`` 模块中,构造函数接受一个参数,原始模板代码。让我们深入挖掘一下
Python的解释器看看它是怎么工作的。
Interactive Interpreter Examples
关于交互式解释器的例子
Throughout this book, we feature example Python interactive interpreter sessions.
You can recognize these examples by the triple greater-than signs (``&&&`` ), which
designate the interpreters prompt. If youre copying examples from this book, dont
copy those greater-than signs.
在本书中,我们喜欢用和Python解释器的交互来举例。你可以通过三个&
( ``&&&`` ) 识别它们,它们相当于Python解释器的提示符。如果你要拷贝例子,请不要拷贝这3个&字符。
Multiline statements in the interactive interpreter are padded with three dots
(``...`` ), for example:
多行语句则在前面加了3个小数点(``...`` ),例如:
Those three dots at the start of the additional lines are inserted by the Python
shelltheyre not part of our input. We include them here to be faithful to the actual
output of the interpreter. If you copy our examples to follow along, dont copy those
这3个点是Python解释器自动加入的,不需要你的输入。我们包含它们是为了忠实呈现解释器的
真实输出。同样道理,拷贝时不要拷贝这3个小数点符号。
From within the project directory created by ``django-admin.py startproject`` (as
covered in Chapter 2), type ``python manage.py shell`` to start the interactive
interpreter. Heres a basic walk-through:
转到project目录(在第二章由 ``django-admin.py startproject`` 命令创建),输入命令 ``python manage.py shell`` 启动交互界面。下面是一些基本操作:
If youre following along interactively, youll see something like this:
如果你跟我们一起做,你将会看到下面的内容:
That ``0xb7d5f24c`` will be different every time, and it
simply the Python identity of the ``Template`` object.
``0xb7d5f24c`` 每次都会不一样,这没什么关系;这只是Python运行时 ``Template`` 对象的ID。
Django Settings
Django 设置
When using Django, you need to tell Django which settings to use. Interactively,
this is typically done using ``python manage.py shell`` , but youve got a few other
options described in Appendix E.
当你使用Django时,你需要告诉Django使用哪个配置。在交互模式下,通常运行命令
``python manage.py shell`` 来做这个,附录E里还有一些其他的一些选项。
When you create a ``Template`` object, the template system compiles the raw template
code into an internal, optimized form, ready for rendering. But if your template
code includes any syntax errors, the call to ``Template()`` will cause a
``TemplateSyntaxError`` exception:
当你创建一个 ``Template`` 对象,模板系统在内部编译这个模板到内部格式,并做优化,做好渲染的准备。如果你的模板语法有错误,那么在调用 ``Template()`` 时就会拋出``TemplateSyntaxError`` 异常:
The system raises a ``TemplateSyntaxError`` exception for any of the following
系统会在下面的情形抛出 ``TemplateSyntaxError`` 异常:
Invalid block tags
无效的块标签
Invalid arguments to valid block tags
无效的参数
Invalid filters
无效的过滤器
Invalid arguments to valid filters
过滤器的参数无效
Invalid template syntax
无效的模板语法
Unclosed block tags (for block tags that require closing tags)
未封闭的块标签 (针对需要封闭的块标签)
Rendering a Template
''''''''''''''''''''
''''''''''''''''''''
Once you have a ``Template`` object, you can pass it data by giving it a *context* .
A context is simply a set of variables and their associated values. A template uses
this to populate its variable tags and evaluate its block tags.
一旦你创建一个 ``Template`` 对象,你可以用 *context* 来传递数据给它。一个context是一系列变量和它们值的集合。模板使用它来赋值模板变量标签和执行块标签。
A context is represented in Django by the ``Context`` class, which lives in the
``django.template`` module. Its constructor takes one optional argument: a
dictionary mapping variable names to variable values. Call the ``Template`` objects
``render()`` method with the context to fill the template:
context在Django里表现为 ``Context`` 类,在 ``django.template`` 模块里。
它的构造函数有一个可选参数:一个字典(映射变量和它们的值)。调用 ``Template`` 对象
的 ``render()`` 方法并传递context来填充模板:
Dictionaries and Contexts
字典和Contexts
A Python dictionary is a mapping between known keys and variable values. A
``Context`` is similar to a dictionary, but a ``Context`` provides additional
functionality, as covered in Chapter 10.
Python的字典数据类型就是关键字和它们值的一个映射。 ``Context`` 和字典很类似,
``Context`` 还提供更多的功能,请看第十章。
Variable names must begin with a letter (A-Z or a-z) and may contain digits,
underscores, and dots. (Dots are a special case well get to in a moment.) Variable
names are case sensitive.
变量名必须由英文字符开始 (A-Z或a-z)并可以包含数字字符、下划线和小数点。
(小数点在这里有特别的用途,稍后我们会讲到)变量是大小写敏感的。
Heres an example of template compilation and rendering, using the sample template
from the beginning of this chapter:
下面是编写模板并渲染的示例:
Lets step through this code one statement at a time:
让我们逐句看看这段代码:
First, we import the classes ``Template`` and ``Context`` , which both live in
the module ``django.template`` .
首先我们导入 (import)类 ``Template`` 和 ``Context`` ,它们都在模块
``django.template`` 里。
We save the raw text of our template into the variable ``raw_template`` . Note
that we use triple quote marks to designate the string, because it wraps over
in Python codde, strings designated with single quote marks
cannot be wrapped over multiple lines.
我们把模板原始文本保存到变量 ``raw_template`` 。注意到我们使用了三个引号来
标识这些文本,因为这样可以包含多行。这是Python的一个语法。
Next, we create a template object, ``t`` , by passing ``raw_template`` to the
``Template`` class constructor.
接下来,我们创建了一个模板对象 ``t`` ,把 ``raw_template`` 作为 ``Template`` 类
的构造的参数。
We import the ``datetime`` module from Pythons standard library, because well
need it in the following statement.
我们从Python的标准库导入 ``datetime`` 模块,以后我们将会使用它。
Then, we create a ``Context`` object, ``c`` . The ``Context`` constructor takes
a Python dictionary, which maps variable names to values. Here, for example, we
specify that the ``person_name`` is ``'John Smith'`` , ``product`` is ``'Super
Lawn Mower'`` , and so forth.
然后,我们创建一个 ``Context`` 对象, ``c`` 。 ``Context`` 构造的参数是Python
字典数据类型,在这里,我们给的参数是 ``person_name`` 值为 ``'John Smith'`` ,
``product`` 值为 ``'Super Lawn Mower'`` ,等等。
Finally, we call the ``render()`` method on our template object, passing it the
context. This returns the rendered templatethat is, it replaces template
variables with the actual values of the variables, and it executes any block
最后,我们在模板对象上调用 ``render()`` 方法,传递 context参数给它。
这是返回渲染后的模板的方法,它会替换模板变量为真实的值和执行块标签。
Note that the warranty paragraph was displayed because the ``ordered_warranty``
variable evaluated to ``True`` . Also note the date, ``April 2, 2009`` , which
is displayed according to the format string ``'F j, Y'`` . (We explain format
strings for the ``date`` filter shortly.)
注意,warranty paragraph显示是因为 ``ordered_warranty`` 的值为 ``True`` .
注意时间的显示, ``April 2, 2009`` , 它是按 ``'F j, Y'`` 格式显示的。
(我们很快就会在 ``date`` 过滤器解释这些格式)
If youre new to Python, you may wonder why this output includes newline
characters (``'\n'`` ) rather than displaying the line breaks. Thats happening
because of a subtlety in the Python interactive interpreter: the call to
``t.render(c)`` returns a string, and by default the interactive interpreter
displays the *representation* of the string, rather than the printed value of
the string. If you want to see the string with line breaks displayed as true
line breaks rather than ``'\n'`` characters, use the ``print`` statement:
``print t.render(c)`` .
如果你是Python初学者,你可能在想为什么输出里有回车换行的字符(``'\n'`` )而不是
显示回车换行?因为这是Python交互解释器的缘故:调用 ``t.render(c)`` 返回字符串,
解释器缺省显示这些字符串的 *真实内容呈现* ,而不是打印这个变量的值。
要显示换行而不是 ``'\n'`` ,使用 ``print`` 语句: ``print t.render(c)`` 。
Those are the fundamentals of using the Django template system: just write a
template, create a ``Template`` object, create a ``Context`` , and call the
``render()`` method.
这就是使用Django模板系统的基本规则:写模板,创建 ``Template`` 对象,创建 ``Context`` ,
调用 ``render()`` 方法。
Multiple Contexts, Same Template
''''''''''''''''''''''''''''''''
同一模板,多个上下文
''''''''''''''''''''''''''''''''
Once you have a ``Template`` object, you can render multiple contexts through it,
for example:
一旦有了 ``模板`` 对象,你就可以通过它渲染多个背景(context),例如:
Whenever youre using the same template source to render multiple contexts like this,
its more efficient to create the ``Template`` object *once* , and then call
``render()`` on it multiple times:
无论何时像这样使用同一模板源渲染多个背景,只创建 *一次*
``模板`` 对象,然后对它多次调用 ``render()`` 将会更加高效。
Djangos template parsing is quite fast. Behind the scenes, most of the parsing
happens via a single call to a short regular expression. This is in stark contrast
to XML-based template engines, which incur the overhead of an XML parser and tend to
be orders of magnitude slower than Djangos template rendering engine.
Django 模板解析非常快捷。大部分的解析工作都是在后台通过对简短正则表达式一次性调用来完成。这和基于 XML 的模板引擎形成鲜明对比,那些引擎承担了 XML 解析器的开销,且往往比 Django 模板渲染引擎要慢上几个数量级。
Context Variable Lookup
'''''''''''''''''''''''
背景变量的查找
'''''''''''''''''''''''
In the examples so far, weve passed simple values in the contextsmostly strings,
plus a ``datetime.date`` example. However, the template system elegantly handles
more complex data structures, such as lists, dictionaries, and custom objects.
在到目前为止的例子中,我们通过 context 传递的简单参数值主要是字符串,还有一个 ``datetime.date`` 范例。然而,模板系统能够非常简洁地处理更加复杂的数据结构,例如list、dictionary和自定义的对象。
The key to traversing complex data structures in Django templates is the dot
character (``.`` ). Use a dot to access dictionary keys, attributes, indices, or
methods of an object.
在 Django 模板中遍历复杂数据结构的关键是句点字符 (``.``)。使用句点可以访问字典的键值、属性、索引和对象的方法。
This is best illustrated with a few examples. For instance, suppose youre passing a
Python dictionary to a template. To access the values of that dictionary by
dictionary key, use a dot:
最好是用几个例子来说明一下。比如,假设你要向模板传递一个 Python 字典。要通过字典键访问该字典的值,可使用一个句点:
Similarly, dots also allow access of object attributes. For example, a Python
``datetime.date`` object has ``year`` , ``month`` , and ``day`` attributes, and you
can use a dot to access those attributes in a Django template:
同样,也可以通过句点来访问对象的属性。比方说, Python 的 ``datetime.date`` 对象有 ``year`` 、 ``month`` 和 ``day`` 几个属性,你同样可以在模板中使用句点来访问这些属性:
This example uses a custom class:
下例使用了一个自定义类:
Dots are also used to call methods on objects. For example, each Python string has
the methods ``upper()`` and ``isdigit()`` , and you can call those in Django
templates using the same dot syntax:
句点还用于调用对象的方法。例如,每个 Python 字符串都有 ``upper()`` 和 ``isdigit()`` 方法,你在模板中可以使用同样的句点语法来调用它们:
Note that you dont include parentheses in the method calls. Also, its not possible
to pass argu you can only call methods that have no required
arguments. (We explain this philosophy later in this chapter.)
注意你不能在方法调用中使用圆括号。而且也无法给该方法传递参数;你只能调用不需参数的方法。(我们将在本章稍后部分解释该设计观。)
Finally, dots are also used to access list indices, for example:
最后,句点也可用于访问列表索引,例如:
Negative list indices are not allowed. For example, the template variable ``{{
items.-1 }}`` would cause a ``TemplateSyntaxError`` .
不允许使用负数列表索引。像 ``{{ items.-1 }}`` 这样的模板变量将会引发
``TemplateSyntaxError`` 异常。
Python Lists
Python 列表类型
Python lists have 0-based indices so that the first item is at index 0, the second
is at index 1, and so on.
Python列表类型的索引是从0开始的,第一个元素的索引是0,第二个是1,以此类推。

我要回帖

更多关于 是什么意思 的文章

 

随机推荐