[Web-SIG] htmlgen

Ian Bicking ianb at colorstudy.com
Thu Oct 30 12:46:05 EST 2003


On Thursday, October 30, 2003, at 11:20 AM, David Fraser wrote:
> I'm not sure about how useful this kind of variable substitution would 
> be for html ... any examples?

defaults = {'username': req.cookie('username', '')}
defaults.update(req.fields)

if request.fields.get('username'):
     defaults['message'] = "<b>Login incorrect</b><br>"

defaults['action'] = '/loginform'

form = '''
<form action="%(action)h" method="POST">
%(message)s
Username: <input type="text" name="username" value="%(username)h"> <br>
Password: <input type="password" name="password" value="%(password)h">
<input type="submit">
</form>
'''.substitute(defaults)


## Using something HTMLgen-ish:

defaults = {'username': req.cookie('username', '')}
defaults.update(req.fields)

if request.fields.get('username'):
     defaults['message'] = html.b("Login incorrect") + html.br()

defaults['action'] = '/loginform'

form = html.form(action=defaults['action'], method="POST")(
     defaults.get('message'),
     'Username: ',
     html.input(type="text", name="username", 
value=defaults.get('username')),
     html.br(),
     'Password: ',
     html.input(type="password", name="password", 
value=defaults.get('password')),
     html.input(type="submit"))


--
Ian Bicking | ianb at colorstudy.com | http://blog.ianbicking.org




More information about the Web-SIG mailing list