From 3cfb941b67e6d48a59c792fec45ab40ecfc7fc5b Mon Sep 17 00:00:00 2001 From: Vosjedev Date: Sun, 26 Oct 2025 10:16:04 +0100 Subject: web.py: add methods to handle 'page registration', semi-static site code --- src/acit/web.py | 19 +++++++++++++++---- 1 file 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 "

Hi

you said %s

" %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) -- cgit