[Twisted-web] guarded example using external login form file

Pedro Sanchez psanchez at nortel.com
Wed Apr 27 14:21:24 MDT 2005


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





More information about the Twisted-web mailing list