views:

535

answers:

7

Hi

I'd like to get suggestions on the best way to serve python scripts up as web pages. Typically I'd like a way for me and my colleagues to write simple web pages with minimal effort ie we focus on the business logic eg creating simple forms etc. Possibly with some way to manage sessions but this is a nice-to-have. It doesn't have to be WYSIWYG as they are developers but we are busy and don't want to spend long turning an idea into reality. It's for internal use so appearances are not paramount.

The software required to enable this should be easy to setup and configure. eg adding new directories and python lib dirs should be easy.

My first instinct is apache or tomcat with mod_python. Any comments / suggestions welcome. Thanks in advance.

Edit - in googling I stumbled onto jython and tried this in tomcat. It seems to load pages quick but from the command line it takes an age. This might be an alternative. Write the presentation in jython servlets and keep any scripts to be used from the command line or web app separate so they can be run with vanilla python. Plus as a java shop this provides a bridge into our jars. Anyone wish to talk me out of this :-) ?

+2  A: 

Give Django a look.

From the website:

"Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design."

zdav
+12  A: 

The new standard is WSGI (Web Server Gateway Interface) and it is supported with mod_wsgi for Apache.

The Web Server Gateway Interface defines a simple and universal interface between web servers and web applications or frameworks for the Python programming language.

Most popular Python web frameworks support WSGI (Django, Pylons, CherryPy, ...).
These frameworks can help you to quickly develop your applications.

You can use CherryPy for very simple applications. Here is a quick What is your name example.

Desintegr
ok, great. Which is quickest to bang out simple pages based on input from files and execute o/s level commands - I don't think we even need a db connection for this.
Ben
A: 

Also take a look at pinax. It is built on top of DJango and it will give you a good head start with your web site.

Vlad
+3  A: 

These kinds of questions usually result in every python web framework known to man being mentioned once or twice. As Desintegr pointed out, wsgi is the standard interface for python web applications. However, if it is a tad too low level for your tastes, I recommend bfg. Here's a simple web app straight from the documentation. No quickstart needed.

from webob import Response
from paste.httpserver import serve
from repoze.bfg.configuration import Configurator

def hello_world(request):
    return Response('Hello world!')

def goodbye_world(request):
    return Response('Goodbye world!')

if __name__ == '__main__':
    config = Configurator()
    config.begin()
    config.add_view(hello_world)
    config.add_view(goodbye_world, name='goodbye')
    config.end()
    app = config.make_wsgi_app()
    serve(app, host='0.0.0.0')

The beauty is bfg can scale up nicely to the most complex applications if needed. And is not opinionated, thus it is very flexible.

If is too much abstraction, I would recommend webob which you can look at as a very thin abstraction on top of the wsgi spec.

Tom Willis
+1 for BFG. It's motto: "Pay for what you eat" means if you really don't care about doing everything under the sun (like Django, or Turbogears) you don't have to import it.This might be the perfect framework for the OP: just enough so you don't need to care about WSGI, but really it sounds like you don't need much else.
RyanWilcox
A: 

You can try out Spyce.

ghostdog74
A: 

You can avoid both mod_python and mod_wsgi by running Tornado (tornadoweb.org). It's the server used by friendfeed. So, map a URL to a class, then create a class that defines get()/post() methods (or whatever HTTP methods you want to support), and "just run it" like a normal python app. Tornado is the web server, and has the bare essentials of a very simple "framework". Check out the demos. I use django on some projects, but I also use Tornado, and I think if your application is really simple and you need to get something done yesterday, the learning curve to get something to happen now is not as onerous in Tornado as it is with Django.

That said, Django has awesome docs, and if you have the time to learn it, the payoff is there.

jonesy
+1  A: 

Actually, it sounds like this may be an excellent use-case for bottle:

Example code that does something

from bottle import route, run

@route('/')
def index():
    return 'Hello World!'

run(host='localhost', port=8080)
RyanWilcox