【问题标题】:Template error , while creating a simple website using python模板错误,同时使用 python 创建一个简单的网站
【发布时间】:2015-12-20 18:26:09
【问题描述】:

我正在使用 web.py 框架创建一个简单的网站。但是当我运行网站时,它给出了模板错误。

我的html文件代码

def with (greeting)
<html>
<head>
<title> "This is a web project"</title>
<body>
<H1>"Yoyo honey singh"</H1>
<H6>greeting<H6>
</body>
</head>
</html>

我的python文件代码

import web

urls = ("/","Index")

app = web.application(urls,globals())

render = web.template.render("\templates")

class Index:
    def GET(self):
        greeting = "HELLO WORLD"
        return render.index(greeting = greeting)

if __name__ == "__main__":
    app.run()

我将 index.html 文件放在模板文件夹中,将 python 脚本放在 bin 文件夹中。目录结构是这样的

D:\网站 网站 姓名 初始化.py 垃圾桶 应用程序.py 测试 初始化.py 文档 模板

【问题讨论】:

    标签: python python-2.7 web.py


    【解决方案1】:

    根据documentation,您应该在模板中的每个python 语句之前放置一个$。因此第一个文件变成了:

    $def with (greeting)
    <html>
    <head>
    <title> "This is a web project"</title>
    <body>
    <H1>"Yoyo honey singh"</H1>
    <H6>$greeting<H6>
    </body>
    </head>
    </html>
    

    【讨论】:

      猜你喜欢
      • 2011-09-23
      • 2021-09-02
      • 2011-02-10
      • 2023-03-03
      • 2019-03-29
      • 2018-01-06
      • 1970-01-01
      • 1970-01-01
      • 2011-09-28
      相关资源
      最近更新 更多