【发布时间】:2015-04-15 15:55:35
【问题描述】:
我想在 wsgi 脚本的 html 部分嵌入一个 forloop。
my_list=[1,2,3]
def my_function(environ,start_response):
start_response('200 OK', [('Content-Type', 'text/html')])
return ['''
<html>
<body>
for i in my_list:
<p>
i
</p>
<body>
</html>
''']
如何使 python 代码在该 wsgi 响应中运行?
【问题讨论】:
-
恭喜!你有问题吗?快点,否则你会得到很多反对票!
-
你为什么要在字符串里面做呢?
-
我无法在没有模板的情况下在 html 中找到使用 python 代码,这对我来说是个问题。抱歉没有 wsgi 经验。
-
如何转义 for 循环并使其在该 html 字符串中作为 python 代码运行。
-
你没有。在字符串之外进行。 就像在任何其他 Python 程序中一样。