Skip to content

Instantly share code, notes, and snippets.

@tonetheman
Created March 4, 2014 18:46
Show Gist options
  • Save tonetheman/9352932 to your computer and use it in GitHub Desktop.
Save tonetheman/9352932 to your computer and use it in GitHub Desktop.
web templates with jinja2 looks more like what i would expect
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