this my file tuto08.py
import os, os.path
import random
import string
import cherrypy
class StringGenerator(object):
@cherrypy.expose
def index(self):
return open('index.html')
@cherrypy.expose
class StringGeneratorWebService(object):
@cherrypy.tools.accept(media='text/plain')
#@cherrypy.expose
def GET(self):
return cherrypy.session['mystring']
#@cherrypy.expose
def POST(self, length=8):
some_string = ''.join(random.sample(string.hexdigits, int(length)))
cherrypy.session['mystring'] = some_string
return some_string
#@cherrypy.expose
def PUT(self, another_string):
cherrypy.session['mystring'] = another_string
#@cherrypy.expose
def DELETE(self):
cherrypy.session.pop('mystring', None)
if __name__ == '__main__':
conf = {
'/': {
'tools.sessions.on': True,
'tools.staticdir.root': os.path.abspath(os.getcwd())
},
'/generator': {
'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
'tools.response_headers.on': True,
'tools.response_headers.headers': [('Content-Type', 'text/plain')]
},
'/static': {
'tools.staticdir.on': True,
'tools.staticdir.dir': './public'
},
'/js': {
'tools.staticdir.on':True,
'tools.staticdir.dir': "./public/js"
},
'/css':{
'tools.staticdir.on':True,
'tools.staticdir.dir': "./public/css"
}
}
webapp = StringGenerator()
webapp.generator = StringGeneratorWebService()
cherrypy.quickstart(webapp, '/', conf)
this my config wsgi got error 404nf POST
import sys
sys.stdout = sys.stderr
import cherrypy
code_directory = "/home/Wicaksono/Kuliah04/"
if code_directory not in sys.path:
sys.path.insert(0, code_directory)
from tuto08 import StringGenerator
application = cherrypy.Application(StringGenerator(),script_name='', config=None)
[edited by admin: formatting]