使用python创建简单网站时出现模板错误

2024-03-29 10:26:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在创建一个简单的网站使用网页.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()

我把索引.html模板文件夹中的文件和bin文件夹中的python脚本。目录结构如下

D:\网站 网站 姓名 初始化.py 箱子 应用程序类型 测验 初始化.py 文件 模板


Tags: 文件代码py模板webtitle网站def
1条回答
网友
1楼 · 发布于 2024-03-29 10:26:35

根据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>

相关问题 更多 >