Django Book 翻译
菜单>:
TOC
返回
原文:
To create this page, well write a *view function* . A view function, or *view* for short, is simply a Python function that takes a Web request and returns a Web response. This response can be the HTML contents of a Web page, or a redirect, or a 404 error, or an XML document, or an image or anything, really. The view itself contains whatever arbitrary logic is necessary to return that response. This code can live anywhere you want, as long as its on your Python path. Theres no other requirementno magic, so to speak. For the sake of putting the code *somewhere* , lets create a file called ``views.py`` in the ``mysite`` directory, which you created in the previous chapter.
翻译:
我们将编写一个 *视图函数* 以创建该页面。所谓的视图函数(或 *视图* ),只不过是一个接受 Web 请求并返回 Web 响应的 Python 函数。实际上,该响应可以是一份网页的 HTML 内容、一次重定向、一条 404 错误、一份 XML 文档、一幅图片,或其它任何东西。视图本身包含返回该响应所需的任意逻辑。该段代码可以随意放置,只要在 Python 的路径设置中就可以了。没有其它要求——也可以说是没有任何奇特之处。为了给这些代码一个 *存身之处* ,让我们在上一章所创建的 ``mysite`` 目录中新建一份名为 ``views.py`` 的文件。
备注:
译者: