我的python示例代码:
def test_print():
code.....
print('Message posted')
test_print()
如何导入:test_print() 到 web2py 中的 HTML 视图?我必须更改 python 代码吗?我的目标是在 HTML 上打印消息
我的python示例代码:
def test_print():
code.....
print('Message posted')
test_print()
如何导入:test_print() 到 web2py 中的 HTML 视图?我必须更改 python 代码吗?我的目标是在 HTML 上打印消息
我认为你不应该像你写的那样做。请参阅 web2py 书中的以下部分:http ://www.web2py.com/books/default/chapter/29/04/the-core#Accessing-the-API-from-Python-modules 。将您的模块“test_print.py”导入您的控制器并将函数的结果传递给您的视图。像这样的东西:
在您的控制器中:
import test_print
def message():
result = test_print.test_print()
return dict(result_to_view=result)
在您看来“message.html”:
<html>
<head></head>
<body>
<h1>My message is: {{=result_to_view}}</h1>
</body>
</html>
知道了?