1
在我的Python代碼我有表中的HTML代碼如何從蟒蛇發送HTML對象的網頁龍捲風
import os.path
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
from tornado.options import define, options
define("port", default=8000, help="run on the given port", type=int)
class IndexHandler(tornado.web.RequestHandler):
def get(self):
tables = "<table> <tr> <th>Company</th> <th>Contact</th> <th>Country</th> </tr> <tr> \
<td>Alfreds Futterkiste</td> <td>Maria Anders</td> <td>Germany</td> </tr> <tr> \
<td>Centro comercial Moctezuma</td> <td>Francisco Chang</td> <td>Mexico</td> </tr> <tr> \
<td>Ernst Handel</td> <td>Roland Mendel</td> <td>Austria</td> </tr> <tr> <td>Island Trading</td> \
<td>Helen Bennett</td> <td>UK</td> </tr> <tr> <td>Laughing Bacchus Winecellars</td> \
<td>Yoshi Tannamuri</td> <td>Canada</td> </tr> <tr> <td>Magazzini Alimentari Riuniti</td> \
<td>Giovanni Rovelli</td> <td>Italy</td> </tr> </table>"
self.render('index.html',tableinfo = tables)
if __name__ == '__main__':
tornado.options.parse_command_line()
app = tornado.web.Application(
handlers=[(r'/', IndexHandler)],
template_path=os.path.join(os.path.dirname(__file__), "templates"))
http_server = tornado.httpserver.HTTPServer(app)
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
我計劃在index.html文件打印此表
<!DOCTYPE html>
<html>
<head><title>Help For table print</title></head>
<body>
<p> {{tableinfo}} </p>
</body>
</html>
不幸的是,它只將字符串打印到html代碼中,並且不使用代碼來創建表格。 你能幫我通過交換變量來顯示錶格。 非常感謝
非常感謝Ben。 – rahram