Skip to content

Instantly share code, notes, and snippets.

@maplpro
Created September 20, 2010 10:39
Show Gist options
  • Save maplpro/587723 to your computer and use it in GitHub Desktop.
Save maplpro/587723 to your computer and use it in GitHub Desktop.
cherrypy simple example and config file
import cherrypy
from jinja2 import Environment, Template, FileSystemLoader
env = Environment( loader = FileSystemLoader('./templates') )
class Root:
@cherrypy.expose
def index(self):
return env.get_template( "index.html" ).render( months = [ '2010-01', '2010-02', '2010-03', '2010-04', '2010-05', '2010-06' ] )
@cherrypy.expose
def cloud(self, data):
import simplejson
res = simplejson.loads( data )
return str( len( res[ 'data' ][ 'items' ] ) )
@cherrypy.expose
def search(self, month):
import urllib2
cherrypy.response.headers[ "Content-Type" ] = "applcation/json"
url = "http://www.googleapis.com/buzz/v1/activities/search?alt=json&max-results=1000&q=from:Mikhael%20Plavskiy%20date:" + month
res = urllib2.urlopen( url )
cherrypy.log( url )
return res.read()
app = cherrypy.quickstart( Root(), config = "config.txt" )
[global]
server.socket_host: '0.0.0.0'
log.error_file: 'site.log'
[/]
tools.staticdir.root = os.getcwd()
[/static]
tools.staticdir.on = True
tools.staticdir.dir = "static"
@Aminot1
Copy link

Aminot1 commented May 29, 2018

shouldn't the config file be ini, config.ini instead of config.txt

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