Created
December 8, 2011 16:10
-
-
Save jbpotonnier/1447451 to your computer and use it in GitHub Desktop.
fun avec bottle, pystache et ... redis
This file contains hidden or 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
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) |
This file contains hidden or 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
<!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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ya vraiment de tout et n'importe quoi ici... ;-)