guarded example using external login form file
Hello, I'm learning nevow and I would appreciate some help modifying this example: http://nevowexamples.adytum.us/sources/guarded.py This "logs in" a user validating it with a username and password. The form used to accept user input is embedded in the code using the stan tags in the NotLoggedIn() class. What I want is to have the login form in an external xhtml file (login.html), like the one that follows my signature. My new NotLoggedIn() class simply looks like this: class NotLoggedIn(rend.Page): """The resource that is returned when you are not logged in""" addSlash = True docFactory = loaders.xmlfile("login.html") I believe the only thing that has to change in the xhtml file (other than the nevow xml space declaration) is on the first line, the "action" thing (guard.LOGIN_AVATAR in guarded.py). But I can't figure out what nevow tag to use there. Can you suggest how to do it? Thanks, -- Pedro <form action="guard.LOGIN_AVATAR" method="post"> <table> <tr> <td>Customer ID:</td> <td><input type="text" name="username" /></td> </tr> <tr> <td>Password:</td> <td><input type="password" name="password" /></td> </tr> </table> <input type="submit" /> </form>
Pedro Sanchez wrote:
Hello,
I'm learning nevow and I would appreciate some help modifying this example:
http://nevowexamples.adytum.us/sources/guarded.py
This "logs in" a user validating it with a username and password. The form used to accept user input is embedded in the code using the stan tags in the NotLoggedIn() class. What I want is to have the login form in an external xhtml file (login.html), like the one that follows my signature. My new NotLoggedIn() class simply looks like this:
class NotLoggedIn(rend.Page): """The resource that is returned when you are not logged in""" addSlash = True docFactory = loaders.xmlfile("login.html")
I believe the only thing that has to change in the xhtml file (other than the nevow xml space declaration) is on the first line, the "action" thing (guard.LOGIN_AVATAR in guarded.py). But I can't figure out what nevow tag to use there.
Can you suggest how to do it?
There is no tag specifically for this. Instead, add a render directive to the <form> element in the HTML template and set the form action in the render_ method ... <form n:render="loginForm"> ... </form> def render_loginForm(self, ctx, data): return ctx.tag(action=url.root.child(guard.LOGIN_AVATAR)) - Matt -- __ / \__ Matt Goodall, Pollenation Internet Ltd \__/ \ w: http://www.pollenation.net __/ \__/ e: matt@pollenation.net / \__/ \ t: +44 (0)113 2252500 \__/ \__/ / \ Any views expressed are my own and do not necessarily \__/ reflect the views of my employer.
On Wed, 2005-27-04 at 20:33 +0100, Matt Goodall wrote:
There is no tag specifically for this. Instead, add a render directive to the <form> element in the HTML template and set the form action in the render_ method ...
<form n:render="loginForm"> ... </form>
def render_loginForm(self, ctx, data): return ctx.tag(action=url.root.child(guard.LOGIN_AVATAR))
- Matt
Thanks for the answer. However, these changes give me: xml.sax._exceptions.SAXParseException: login.html:7:2: unbound prefix when I visit the page. Line 7 in "login.html" is the one with <form ...>. I tried with and without the method="post" in this line. This is my render method, class LoginPage(rend.Page): """The resource that is returned when you are not logged in""" addSlash = True action = guard.LOGIN_AVATAR docFactory = loaders.xmlfile("login.html") def render_loginForm(self, ctx, data): return ctx.tag(action=url.root.child(guard.LOGIN_AVATAR)) And this is my login.html file <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" xmlns:nevow="http://nevow.com/ns/nevow/0.1"> <head> <title>Login Page</title> </head> <body> <form n:render="loginForm" method="post"> <table> <tr> <td>Customer ID:</td> <td><input type="text" name="username" /></td> </tr> <tr> <td>Password:</td> <td><input type="password" name="password" /></td> </tr> </table> <input type="submit" /> </form> </body> </html> -- Pedro
Pedro Sanchez wrote:
xml.sax._exceptions.SAXParseException: login.html:7:2: unbound prefix
when I visit the page. Line 7 in "login.html" is the one with <form ...>. I tried with and without the method="post" in this line. This is my render method,
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" xmlns:nevow="http://nevow.com/ns/nevow/0.1"> ^^^^^
<form n:render="loginForm" method="post"> ^
"n" != "nevow"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" xmlns:nevow="http://nevow.com/ns/nevow/0.1"> ^^^^^
<form n:render="loginForm" method="post"> ^
"n" != "nevow" Thanks, that was the problem.
Please bear with me for a little while more. I have two more questions: 1) I don't understand what the third parameters(noLogout and resc.logout) in these return statements do: def requestAvatar(self, avatarId, mind, *interfaces): ... return (inevow.IResource, resc, noLogout) ... return (inevow.IResource, resc, resc.logout) Can you give me a hint? 2) Now I'm trying to move the LoggedIn class into an external "welcome.html" file. I get this error (files follow my signature): exceptions.AttributeError: 'NoneType' object has no attribute 'load' I get this error even without using any nevow tags in welcome.html. Thank you for your time, -- Pedro This is my new LoggedIn class: class LoggedIn(rend.Page): """The resource that is returned when you login""" addSlash = True docfactory = loaders.xmlfile("welcome.html") def render_welcome(self, ctx, data): return ctx.tag[ "Hello, %s!" % data] def render_logout(self, context, data): return ctx.tag(href=url.root.child(guard.LOGOUT_AVATAR)) def logout(self): print "%s logged out!" % self.original And this is welcome.html: <html> <head> <title>Welcome!</title> </head> <body> <h1>nevow:render="welcome"</h1> <a nevow:render=logout">Logout</a> </body> </html>
Quoting Pedro Sanchez <psanchez@nortel.com>:
1) I don't understand what the third parameters(noLogout and resc.logout) in these return statements do:
def requestAvatar(self, avatarId, mind, *interfaces): ... return (inevow.IResource, resc, noLogout) ... return (inevow.IResource, resc, resc.logout)
Can you give me a hint?
It's the method called when you access the guard.LOGOUT_AVATAR url. So "noLogout" when you're Anonymous (you can't log out when you're anonymous), and resc.logout which is a specific method.
2) Now I'm trying to move the LoggedIn class into an external "welcome.html" file. I get this error (files follow my signature):
exceptions.AttributeError: 'NoneType' object has no attribute 'load'
docfactory != docFactory -- Thomas
On Thu, 2005-28-04 at 17:45 +0200, Thomas HERVE wrote:
Quoting Pedro Sanchez <psanchez@nortel.com>:
1) I don't understand what the third parameters(noLogout and resc.logout) in these return statements do:
def requestAvatar(self, avatarId, mind, *interfaces): ... return (inevow.IResource, resc, noLogout) ... return (inevow.IResource, resc, resc.logout)
Can you give me a hint?
It's the method called when you access the guard.LOGOUT_AVATAR url. So "noLogout" when you're Anonymous (you can't log out when you're anonymous), and resc.logout which is a specific method.
resc.logout has this single statement print "%s logged out!" % self.original Why is then that I never see this message? After I login, I click "Logout", and it takes me back to the login page. Or is it that it goes by so quickly that I don't see it?
2) Now I'm trying to move the LoggedIn class into an external "welcome.html" file. I get this error (files follow my signature):
exceptions.AttributeError: 'NoneType' object has no attribute 'load'
docfactory != docFactory
Dummy me! thanks.
On Thu, 2005-28-04 at 12:20 -0400, Sanchez, Pedro [CAR:1A10:EXCH] wrote:
On Thu, 2005-28-04 at 17:45 +0200, Thomas HERVE wrote:
Quoting Pedro Sanchez <psanchez@nortel.com>:
1) I don't understand what the third parameters(noLogout and resc.logout) in these return statements do:
def requestAvatar(self, avatarId, mind, *interfaces): ... return (inevow.IResource, resc, noLogout) ... return (inevow.IResource, resc, resc.logout)
Can you give me a hint?
It's the method called when you access the guard.LOGOUT_AVATAR url. So "noLogout" when you're Anonymous (you can't log out when you're anonymous), and resc.logout which is a specific method.
resc.logout has this single statement print "%s logged out!" % self.original
Why is then that I never see this message? After I login, I click "Logout", and it takes me back to the login page. Or is it that it goes by so quickly that I don't see it?
Sorry, I know, this is stdout stuff.
2) Now I'm trying to move the LoggedIn class into an external "welcome.html" file. I get this error (files follow my signature):
exceptions.AttributeError: 'NoneType' object has no attribute 'load'
docfactory != docFactory
Dummy me! thanks.
_______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
participants (4)
-
Matt Goodall
-
Pedro Sanchez
-
Thomas HERVE
-
Tommi Virtanen