Web2py - 设置标题&视图中的元标记

时间:2015-02-21 18:13:11

标签: web2py

我试图为每个视图设置唯一的标题和元标记。如果我在我的视图顶部以下列方式设置标签......

{{
response.title='My Product view'
response.meta.keywords='phones,calls,smartphone'
response.meta.description='This is a phone seller site made with web2py'
response.meta.author='me'
}}

{{extend 'layout.html'}} 

...标签似乎设置正确,标题标签除外。如果我检查头部,标题标签不会出现。

如果我使用或不使用head标签以下列方式设置标签......

<head>
<title>My Product view</title>
<meta name="description" content='This is a phone seller site made with web2py'>
<meta name="keywords" content='phones,calls,smartphone'>
<meta name="author" content='me'>
</head> 

{{extend 'layout.html'}} 

...标签似乎正常工作,包括标题标签,但我的所有表单输入的高度都丢失了20个像素。

有谁知道为什么我会遇到这种情况?在视图中设置这些项目的最佳方法是什么?

1 个答案:

答案 0 :(得分:1)

首先,不要在{{extend 'layout.html'}}之前放置任何HTML,因为在{layout.html'中HTML的开头之前将插入extend之前的任何内容,其本身以开头{{开头}开始1}}和<html>标记(因此,您的示例会在文档的开始<head>标记之前插入整个<head>部分,然后包含另一个<html>部分。< / p>

设置<head>,你应该可以正常工作。但是,您的“layout.html”必须包含response.title部分中的以下内容:

<head>

脚手架应用的'layout.html'包含similar line(如果没有<title>{{=response.title}}</title> 则会有后退。)