简体   繁体   English

Django 中的“渲染”是什么意思?

[英]What does “render” mean in Django?

What does it mean to "render a template" or to "render a form" in Django?在 Django 中“渲染模板”或“渲染表单”是什么意思? Example 1: "Generally a view retrieves data according to the parameters, loads a template and renders the template with the retrieved data.示例1:“通常视图根据参数检索数据,加载模板并使用检索到的数据呈现模板。

Example 2: "Rendering a form in a template involves nearly the same work as rendering any other kind of object"示例 2:“在模板中呈现表单涉及与呈现任何其他类型的对象几乎相同的工作”

Would the meaning of render in the above two examples be to "provide" or give"?上面两个例子中render的意思是“提供”还是“给予”?

These etymologies given on Wiktionary stand:维基词典上给出的这些词源

(transitive) To interpret, give an interpretation or rendition of. (及物)解释、解释或演绎。

(transitive) To translate into another language. (及物)翻译成另一种语言。

(transitive, computer graphics) To transform (a model) into a display on the screen or other media. (传递,计算机图形)将(模型)转换为屏幕或其他媒体上的显示。

That is, the code describing your form, or the template describing your page, is rendered into the final HTML form.也就是说,描述您的表单的代码或描述您的页面的模板将呈现为最终的 HTML 表单。

Rendering a template is indeed always about producing content, but for a slightly wider description of content.渲染模板确实总是关于生成内容,但是对于内容的更广泛的描述。 It could be a chunk of html, for example an ajax call to get new items might produce some html describing the new items, but it doesn't have to be.它可能是一大块 html,例如一个 ajax 调用来获取新项目可能会产生一些 html 描述新项目,但它不是必须的。

creds.信用。 Frederick Cheung弗雷德里克·张

You are looking for generic term "templating": https://wiki.python.org/moin/Templating您正在寻找通用术语“模板”: https://wiki.python.org/moin/Templating

TLDR; TLDR; It's common practice to split View and Models.拆分视图和模型是常见的做法。 In this case View is templates, eg html file.在这种情况下,视图是模板,例如 html 文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM