Skip to content

Instantly share code, notes, and snippets.

@lbolla
Created May 2, 2014 07:52
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 lbolla/bb7af2bfb536aec2f79c to your computer and use it in GitHub Desktop.
Save lbolla/bb7af2bfb536aec2f79c to your computer and use it in GitHub Desktop.
import random
import string
import cherrypy
class StringGenerator(object):
@cherrypy.expose
def index(self):
return """<html>
<body>
<form method="get" action="generate">
<input type="text" value="8" name="length" />
<button type="submit">Give it now!</button>
</form>
</body>
</html>"""
@cherrypy.expose
def generate(self, length=8):
some_string = ''.join(random.sample(string.hexdigits, int(length)))
cherrypy.session['mystring'] = some_string
return some_string
@cherrypy.expose
def display(self):
return cherrypy.session['mystring']
if __name__ == '__main__':
favconfig = {
"/favicon.ico": {
"tools.staticfile.on": True,
"tools.staticfile.filename": "/tmp/favicon.ico",
"tools.staticfile.content_types": {"ico": "image/x-icon"},
}
}
cherrypy.quickstart(StringGenerator(), "/", favconfig)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment