Sample GSD App

"""Record and display shout outs for the life of the server."""

import gsd

TEMPLATE = """
<html>
<head>
<title>Shout Outs!</title>
</head>
<body>
<form action="/" method="get">
<input name="shout">
<input type="submit" value="Shout!">
</form>
<?
for shout in self.shout_outs:
print shout, '<br>'
?>
</body>
</html>
"""

class ShoutOuts(gsd.App):

"""A simple GSD app that records shout outs for the life of the server."""

def __init__(self):
self.shout_outs = []

def GET_(self, shout=None):
"""Display shout outs and form to add new ones."""
if shout is not None:
self.shout_outs.append(shout[0])
self.Render(TEMPLATE, locals())

def GET_reset(self):
"""Reset the list of shoutouts."""
self.shout_outs = []
self.Redirect('/')

if __name__ == '__main__':
app = ShoutOuts()
print 'http://localhost:8000/'
app.Serve('localhost', 8000)

No comments:

Post a Comment