diff options
| author | Vosjedev <vosje@vosjedev.net> | 2025-10-26 10:16:04 +0100 |
|---|---|---|
| committer | Vosjedev <vosje@vosjedev.net> | 2025-10-26 10:16:04 +0100 |
| commit | 3cfb941b67e6d48a59c792fec45ab40ecfc7fc5b (patch) | |
| tree | 93fd09717f387b27ba62792e60c37f05bdc0e41e | |
| parent | 68a3ba2bea76144e4b0a0fad10beb18599eabc1d (diff) | |
| download | acit-3cfb941b67e6d48a59c792fec45ab40ecfc7fc5b.tar.gz acit-3cfb941b67e6d48a59c792fec45ab40ecfc7fc5b.tar.bz2 acit-3cfb941b67e6d48a59c792fec45ab40ecfc7fc5b.tar.xz | |
web.py: add methods to handle 'page registration', semi-static site code
| -rw-r--r-- | src/acit/web.py | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/acit/web.py b/src/acit/web.py index 15cbe46..7c6c054 100644 --- a/src/acit/web.py +++ b/src/acit/web.py @@ -4,15 +4,26 @@ import cherrypy class Server(): def __init__(self): - pass + cherrypy.engine.subscribe("newpage",self.registerpage) + self.pages={} + + def registerpage(self,path,content): + self.pages[path]=content @cherrypy.expose def index(self,quote="nothing"): - return "<html><body><h1>Hi</h1><p>you said %s</p></body></html>" %quote + return "Index" @cherrypy.expose - def default(self,*path,**kwargs): - return "Hello world" + def default(self,*pathlist,**kwargs): + from os.path import normpath + path=normpath("/".join(pathlist)) + if path in self.pages: + return self.pages[path] + else: + from .html import notfound + cherrypy.response.status=404 + return notfound.format(path=path) |
