floydophone at gmail.com
Thu Nov 18 07:50:43 MST 2004
I've been discussing this with a few people on #twisted.web, and after
reviewing the code, I've decided it's time to show it off to a larger
audience. I've committed a new package called wolf (flow backwards).
It's available at http://www.divmod.org/svn/Nevow/sandbox/phunt/wolf/.
Download that and drop it into your site-packages.
Essentially, it lets you write web applications in a linear style
instead of writing a bunch of ugly FSMs. For example, let's say you
wanted to write a user registration system...
from nevow import wolf
# assume RegisterPage, ProfilePage, and SuccessPage are nevow Pages
# RegisterPage asks for username and desired password
# ProfilePage asks for name and age
# SuccessPage is success
regpage = wolf.callable_page(RegisterPage) # simplifies usage within wolf
profpage = wolf.callable_page(ProfilePage)
successpage = wolf.callable_page(SuccessPage)
def _validate_reg(self, req):
# TODO: make sure everything is ok with the form
def _validate_prof(self, req):
def _regform(self, req):
# underscore-prefixed methods cannot be called from outside
def _profform(self, req):
def index(self, req):
# this is the whole register routine
You can connect this to a Nevow site by using:
Then, you can request it by going to:
Download the code, try it out. If you run Stackless, you get to use
the back button, otherwise you're stuck with not being able to go
back. There is an example.py file which is a fully working example of
a guess-the-number game.
More information about the Twisted-web