Created
March 4, 2014 18:46
-
-
Save tonetheman/9352932 to your computer and use it in GitHub Desktop.
web templates with jinja2 looks more like what i would expect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import web | |
import jinja2 | |
urls = ( | |
"^/scale$", "Scale", | |
) | |
PAGE2 = """ | |
<html> | |
<body> | |
id : {{ id }}<br /> | |
scale : {{ scale }}<br /> | |
</body> | |
</html> | |
""" | |
class Scale: | |
def handle(self): | |
inp = web.input() | |
myid = -1 | |
if inp.has_key("id"): | |
myid = inp.id | |
scale = -1 | |
try: | |
scale = float(inp.scale) | |
except: | |
pass | |
data = { "scale" : scale, "id" : myid } | |
tmpl = jinja2.Template(PAGE2) | |
return tmpl.render(data) | |
def GET(self): | |
inp = web.input() | |
return self.handle() | |
def POST(self): | |
inp = web.input() | |
return self.handle() | |
if __name__ == "__main__": | |
app = web.application(urls,globals()) | |
app.run() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment