Http server

G

Gert Cuykens

so far this works

<code>
import cherrypy
import os.path

class Http:

def index(self):
f = open(os.path.join(os.path.dirname(__file__), '../htm/index.htm'))
xml = f.read()
f.close()
return xml
index.exposed = True

cherrypy.tree.mount(Http())

if __name__ == '__main__':
cherrypy.config.update(os.path.join(os.path.dirname(__file__),
'server.conf'))
cherrypy.server.quickstart()
cherrypy.engine.start()
</code>

I would like a cute secretary for Christmas but i dont think i will
get one. So i need to find a way to scan a directory. And map all
files inside the directory and generate a class member like

<code>
def filename(self):
f = open(os.path.join(os.path.dirname(__file__), '../htm/filename'))
xml = f.read()
f.close()
return xml
filename.exposed = True
</code>

Any idea or cute secretary maybe ?
 
F

fumanchu

Gert said:
so far this works

<code>
import cherrypy
import os.path

class Http:

def index(self):
f = open(os.path.join(os.path.dirname(__file__), '../htm/index.htm'))
xml = f.read()
f.close()
return xml
index.exposed = True

cherrypy.tree.mount(Http())

if __name__ == '__main__':
cherrypy.config.update(os.path.join(os.path.dirname(__file__),
'server.conf'))
cherrypy.server.quickstart()
cherrypy.engine.start()
</code>

I would like a cute secretary for Christmas but i dont think i will
get one. So i need to find a way to scan a directory. And map all
files inside the directory and generate a class member like

<code>
def filename(self):
f = open(os.path.join(os.path.dirname(__file__), '../htm/filename'))
xml = f.read()
f.close()
return xml
filename.exposed = True
</code>

Any idea or cute secretary maybe ?

The cute secretary's name is "cherrypy.tools.staticdir".
Check out her resume at http://www.cherrypy.org/wiki/StaticContent


Robert Brewer
System Architect
Amor Ministries
(e-mail address removed)
 
G

Gert Cuykens

The cute secretary's name is "cherrypy.tools.staticdir".
I think i am in love :)

Cant believe this just works out

<code>
import os.path
import cherrypy
pwd = os.path.dirname(os.path.abspath(__file__))

class Http:

_cp_config = {'tools.sessions.on': True}
@cherrypy.expose
def index(self):
f = open(os.path.join(pwd, '../htm/index.htm'))
xml = f.read()
f.close()
return xml

if __name__ == '__main__':
cherrypy.config.update({'server.socket_port': 8080,
'server.thread_pool': 10,
'environment': 'production',
'log.screen': True})
conf = {'/': {'tools.staticdir.root': os.path.join(pwd, '../htm')},
'/css': {'tools.staticdir.on': True,
'tools.staticdir.dir': os.path.join(pwd, '../css')},
'/js': {'tools.staticdir.on': True,
'tools.staticdir.dir': os.path.join(pwd, '../js')}}
cherrypy.quickstart(Http(), '/', config=conf)
</code>
 
G

Gert Cuykens

Does anybody know how to redirect a post request ?

i have a js file that does a post request to a /php/action.php file
and i would like for the secretary to just do the action method
instead that is defined in her python Http class book, so i can run
both php and python without changing the static source code at 2
different ports head to head to see witch one can handle the most
requests ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top