Web Based Front End?

Jeremiah Dodds jeremiah.dodds at gmail.com
Fri May 8 04:31:07 EDT 2009


On Fri, May 8, 2009 at 2:52 AM, <baseelinger at yahoo.com> wrote:

> So, my question is what is the best method to be able to have a user
> enter specific data on a web page, have that data be passed to the
> Python script and then have the output returned to the web page?
> Essentially, I want to use a web based front end to accomplish the
> same thing that the IDLE GUI does, (asks me a few questions, I answer
> them, it builds a configuration file and prints it to the screen).
>
>
There isn't a best way, really.

I'm partial to CherryPy. A minimal example would look like so:

-------------------------------
import cherrypy

class Root(object):
    page = "<html><head><title></title></head><body>%s</body></html>"
    @cherrypy.expose
    def enter_data(self, data):
        return self.page % ("You entered: " + data,)

    @cherrypy.expose
    def index(self):
        form = """
        <form id="aform" name="aform" action="enter_data" method="POST">
          <textarea name="data">Enter some stuff here</textarea>
          <input type="submit" value="Submit"/>
        </form>
        """
        return self.page % form

if __name__ == '__main__':
    cherrypy.quickstart(Root())

-----------------------------------

Note, I wouldn't actually recommend using string building like that for
returning pages unless your app is seriously trivial. I use Genshi for
templating, the tutorial that they have is very nice (and uses cherrypy).

There's a plethora of different ways to build web apps in python. In all
reality, you should probably try out a few and see what suits your tastes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090508/1e3b0476/attachment-0001.html>


More information about the Python-list mailing list