【发布时间】:2015-09-17 17:51:27
【问题描述】:
我确定我在教程中遗漏了一些非常明显的东西,但我尝试通过实现一个简单的脚本和 html 页面来学习 webpy 框架。
这是我从命令行运行以启动“服务器”的主脚本(我在 Index 类中没有正确工作/设置的 POST 函数,但只是尝试使用 GET 函数开始正常工作):
import web
import sys
sys.path.insert(0, '/Users/seanjarp/PythonLearnings/projects/GAME/ChipChippersonGame')
from ChipChippersonGame import ChipChippersonGame
urls = (
'/testhtml', 'Index'
)
app = web.application(urls, globals())
render = web.template.render('templates/')
class Index(object):
def GET(self):
return render.testhtml(ChipChippersonGame)
# return render.testhtml()
#def POST(self):
# form = web.input(playerinput="HiChip")
# user_response = ChipChippersonGame.next_scene(form)
if __name__ == "__main__":
app.run()
上面的这个脚本是在另一个导演中导入另一个脚本,目前我已经简化为只有一个打印语句来保持简单(导入工作正常):
print "ChipChippersonGame script is being called"
testhtml 文件如下所示:
$def with (ChipChippersonGame)
<html>
<head>
<title>What's Up!</title>
</head>
<body>
$if ChipChippersonGame:
$ChipChippersonGame
$else:
<em>Script is not being called!</>
</body>
</html>
显然,例如,当我将其加载到浏览器中时:
http://0.0.0.0:4141/testhtml
它将以下内容打印到浏览器:
<module 'ChipChippersonGame.ChipChippersonGame' from '/Users/seanjarp/PythonLearnings/projects/GAME/ChipChippersonGame/ChipChippersonGame`/ChipChippersonGame.pyc
我做错了什么导致ChipChippersonGame.py 脚本中的打印语句无法打印到浏览器?
我假设我搞砸了我在 testhtml.html 文件中调用或设置函数的方式。
【问题讨论】:
标签: python python-2.7 web.py web-frameworks