crowfly.net  

HtmlPage

HtmlPage is a lightweight HTML/CGI Framework for Python. It is an HTML abstraction layer.

The Source consists of three files

Example usage

Simplest Example

Put some text on the page.


 #!/usr/bin/python
 
 from htmlpage import HtmlPage
 
 class MyPage(HtmlPage):
     
     def __init__(self):
         HtmlPage.__init__(self, "Now's the time")
 
     def getHtmlContent(self):
         return '''
         <h3>My Page</h3>
         <p>Now is the time for all good folks 
         to come to the aid of their country.</p>
         '''
 
 if __name__ == '__main__':
     myPage = MyPage()
     myPage.go()

Do Something Example

Override the process method to process GET and POST data.

 #!/usr/bin/python
 
 from htmlpage.htmlpage import HtmlPage
 
 class DoSomething(HtmlPage):
     
     def __init__(self):
         HtmlPage.__init__(self, "Do Something")
         self.bgcolor = 'lightblue'
         # Turn on/off Debug CGI
         #self.debug_cgi = True 
 
     def process(self):
         HtmlPage.process(self)
         if 'bgcolor' in self.form:
             self.bgcolor = self.form['bgcolor'].value
             
     def getHtmlContent(self):
         output = ''
         output += '<h3>Do Something</h3>'
         output += '<div style="background-color: %s;">' % self.bgcolor
         output += '<p style="padding: 100px">Choose background color:'
         output += self.getColorMenu()
         output += '</div>'
         return output
 
def getColorMenu():
    return '''
    <select name="bgcolor" onChange="javascript:submit();">
       <option value="lightblue">lightblue</option>
       <option value="lightgreen">lightgreen</option>
       <option value="lightyellow">lightyellow</option>
    </select>'''
 
 if __name__ == '__main__':
     p = DoSomething()
     p.go()