aspen handling of form post

1 view
Skip to first unread message

infotek

unread,
Mar 15, 2008, 12:55:43 PM3/15/08
to aspen-users
Hi,

I'm interested in using aspen as a configuration interface... where
aspen serves an HTML form, pre-populated based on the contents of a
configuration file. I would like the values to be adjustable by the
users who could then post the page back to aspen. Finally i would
like aspen to do some sanity checks on the data that was submitted and
write the data back to the config file.

Basically, I want to allow a user to modify the configuration file
of an application I'm working on using a web browser.

At first look, I think aspen can do it via its handlers. I wanted
to ask before I begin to invest significant amount of time
understanding python and aspen more as I'm not that good of a
programmer.

-Jason Ellison

PS: this is related to a project for turning old laptops into picture
frames named "flickr-pitchr". The program is wrtten in python and
downloads images from flickr.com for display via SDL on a framebuffer
device.

http://code.google.com/p/flickr-pitchr/

Chad Whitacre

unread,
Mar 17, 2008, 10:18:31 AM3/17/08
to infotek, aspen-users
Jason,

Yeah, should work. Do you have aspen installed? Try getting a
stdlib simplate running:

http://www.zetadev.com/software/aspen/0.8/doc/html/api-handlers-simplates.html

Simplates wiring example here:

http://www.zetadev.com/software/aspen/0.8/doc/html/handlers-conf.html

Then write your simplate like this:


"""
import os

CONF = os.path.join('path', 'to', 'file.conf')


^L

if environ['REQUEST_METHOD'] == 'POST': # <could be wrong API!>
blah = parse_form(environ)
fp = open(CONF)
fp.write(blah)


^L
<html>
<form action="<self>" method="POST">
...
</form>
</html>
"""


Check WebOb for environ wrapper:

http://pythonpaste.org/webob/

hth,
chad

Reply all
Reply to author
Forward
0 new messages