[albatross-users] Getting things *out* of session_vars?
VanL
vlindberg at verio.net
Thu Apr 24 06:34:02 EST 2003
Here is a pretty minimal example that shows the page_enter problem.
login.py: ================================
def page_enter(ctx):
if not hasattr(ctx.locals, 'login_message'):
setattr(ctx.locals, 'login_message', 'Please enter your
username and password:')
if not hasattr(ctx.locals, 'user'):
setattr(ctx.locals, 'user', '')
def page_process(ctx):
if ctx.req_equals('login'):
if hasattr(ctx.locals, 'user') and hasattr(ctx.locals, 'passwd'):
user, passwd = ctx.get_value('user'), ctx.get_value('passwd')
if user and passwd:
if authenticate(user, passwd):
ctx.add_session_vars('user', 'passwd')
ctx.set_page('controlpanel')
return
def page_display(ctx):
ctx.run_template('login.html')
==========================================
login.html: ===================================
<html><head></head><body>
<al-form method="post">
<h1><al-value expr="login_message"></h1>
<al-input type="text" name="user" expr="user">
<al-input type="text" name="passwd">
</al-form>
</body></html>
==========================================
Run this and it shows up fine the first time. If you submit true values
for user and passwd, it will forward just fine. However, if you submit
bad values:
Template traceback (most recent call last):
File "/www/htdocs/albatross/new_cust_wizard/login.html", line 16, in al-form
<al-form method="post">
File "/www/htdocs/albatross/new_cust_wizard/login.html", line 21, in al-value
Traceback (most recent call last):
[Snip]
File "<albatross>", line 0, in ?
NameError: name 'login_message' is not defined
I thought that once I had defined a default value in page_enter, it
would stay set. That is why I thought that perhaps page_enter was not
being called. Could someone point out my error?
Thanks,
VanL
More information about the Albatross-users
mailing list