Skip to content

Instantly share code, notes, and snippets.

@ccdjh
Created January 29, 2012 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccdjh/1701355 to your computer and use it in GitHub Desktop.
Save ccdjh/1701355 to your computer and use it in GitHub Desktop.
import os
import tornado.wsgi
import tornado.web
import sae
import json
class MainHandler(tornado.web.RequestHandler):
def get(self):
t = '''{"b":"1","c":"1","d":"1"}'''
tt = '''[{"b":"1","c":"1","d":"1"},{"b":"2","c":"2","d":"2"},{"b":"3","c":"3","d":"3"}]'''
ttt = '''{"a": [{"c": "1", "b": "1", "d": "1"}, {"c": "2", "b": "2", "d": "2"}, {"c": "3", "b": "3", "d": "3"}], "f": "123456"}'''
e = json.loads(t)
eee = json.loads(ttt)
self.write(t)
self.write(tt)
self.write(ttt)
self.write(e["b"])
self.write("Hello, world")
self.write(eee["f"])
class MainToHandler(tornado.web.RequestHandler):
def get(self):
t = '''{"b":"1","c":"1","d":"1"}'''
te = json.loads(t)
tt = '''[{"b":"1","c":"1","d":"1"},{"b":"2","c":"2","d":"2"},{"b":"3","c":"3","d":"3"}]'''
tte = json.loads(tt)
ttt = '''{"a": [{"c": "1", "b": "1", "d": "1"}, {"c": "2", "b": "2", "d": "2"}, {"c": "3", "b": "3", "d": "3"}], "f": "123456"}'''
ttte = json.loads(ttt)
template_values = {}
template_values['t'] = t
template_values['te'] = te["b"]
template_values['tt'] = tt
template_values['tte'] = tte[0]
template_values['ttes'] = tte[0]["b"]
template_values['ttt'] = ttt
template_values['ttte'] = ttte
template_values['tttes'] = ttte["a"]
template_values['tttest'] = ttte["a"][0]
template_values['tttestt'] = ttte["a"][0]["b"]
template_values['f'] = ttte["f"]
path = os.path.join(os.path.dirname(__file__),'to.html')
self.render(path,tpl=template_values)
app = tornado.wsgi.WSGIApplication([
(r"/", MainHandler),
(r"/to", MainToHandler),
])
application = sae.create_wsgi_app(app)
"""
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta content="True" name="HandheldFriendly" />
<meta content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0; name='viewport'" />
<title>to</title>
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="alternate" type="application/atom+xml" href="/index.xml" />
<style type="text/css"><!--
html {padding: 0px;margin: 0px;font-family: "Helvetica Neue", "Luxi Sans", "DejaVu Sans", Tahoma, "STHeiti";}
body {background-color: #B4D9F1;padding: 0px;margin: 0px;}
a:link, a:visited, a:active {color: #336699;text-decoration: none;}
a:hover {color: #222;text-decoration: none;}
#Main{width:920px;margin:30px auto;padding: 20px;-webkit-box-shadow: rgba(0, 0, 0, 0.09) 0px 1px 3px;background-color: white;border: 1px solid #CCC;border-bottom-left-radius: 5px 5px;border-bottom-right-radius: 5px 5px;border-top-left-radius: 5px 5px;border-top-right-radius: 5px 5px;text-align: right;}
--></style>
</head>
<body>
<div id="Main">
<div>
<p>{{ tpl['t'] }}</p><p>{{ tpl['te'] }}</p>
<hr>
<p>{{ tpl['tt'] }}</p><p>{{ tpl['tte'] }}</p><p>{{ tpl['ttes'] }}</p>
<hr>
<p>{{ tpl['ttt'] }}</p><p>{{ tpl['ttte'] }}</p><p>{{ tpl['tttes'] }}</p><p>{{ tpl['tttest'] }}</p><p>{{ tpl['tttestt'] }}</p>
<hr>
<p>{{ tpl['f'] }}</p>
</div>
</div>
</body>
</html>
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment