Skip to content

Instantly share code, notes, and snippets.

@jbpotonnier
Created December 8, 2011 16:10
Show Gist options
  • Save jbpotonnier/1447451 to your computer and use it in GitHub Desktop.
Save jbpotonnier/1447451 to your computer and use it in GitHub Desktop.
fun avec bottle, pystache et ... redis
from bottle import Bottle
import bottle
import pystache
import redis
import json
app = Bottle()
redisse = redis.Redis()
def mustache(template, context):
stringTemplate = open('views/%s.html' % template).read()
return pystache.render(stringTemplate, context)
@app.route('/stuff')
@app.route('/stuff/')
@app.route('/stuff/<autre>')
def affiche(autre = 'scon'):
stuff = [{'name': 'hammer'}, {'name': 'to fall'}]
return mustache(template='stuff', context={'stuff': stuff, 'title': 'ta race %s' % autre})
@app.route('/redis/<command>/<args:path>')
def redis(command, args):
return json.dumps(redisse.execute_command(command, *(args.split('/'))))
if __name__ == '__main__':
bottle.debug()
bottle.run(app, host='localhost', port=8000, reloader=True)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>{{title}}</title>
</head>
<body>
<ul>
{{#stuff}}
<li>{{name}}</li>
{{/stuff}}
</ul>
</body>
</html>
@jpcaruana
Copy link

ya vraiment de tout et n'importe quoi ici... ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment