views:

1626

answers:

6

I'm just getting into python on the web. I have a simple linux (CentOS) server with python installed into apache via mod_python. It all works great, but I don't really understand what to do about the Handler. It works, but I have to do low-level things like, at minimum, set the proper content_type of the request before I write out anything (I also have to manually write on the req stream, which seems very low-level).

Now, I understand what's happening, and why I have to do this, but what I am wondering is if there are any frameworks that exist somewhere that I can use to abstract some of this stuff. Django, Grok, Pylons and all these frameworks seem more like Application Frameworks, or CMS Frameworks. Sort of like how ASP.NET is a Web Framework: it abstracts low-level server things and provides niceties for you, whereas ADXStudio/Sitefinity (I guess?) is a CMS system/framework that you can build/expand upon. Is this a correct assessment?

Can you help me straighten out this app framework/web framework issue, and maybe englighten me as to the Python options out there and what specifically they are/do? For instance now that I am thinking about it, CherryPy struck me as "web framework"-y, is this a correct assessment as well?

Any help is greatly appreciated.

+2  A: 

Have you considered just hacking one of your own?

A simple action framework (that's basically what you're talking about here) is actually pretty simple, and with a dynamic language like Python it should be even simpler.

It will require perhaps a bit of "advanced" python knowledge (I don't know how comfortable you are with Python), reflection mostly, perhaps, but it's really not a great leap.

As a benefit, you will have a better understanding of your request cycle.

The other thing to look for is some kind of "Python Server Pages", specifically something that lets you render Python data in to an HTML page. There are several of these (also look at Python templating tools, same thing really).

The goal here is that you can off the shelf the "view" layer, and then use your little mini framework for actual control and dispatch.

At a minimum it is an interesting project, and I think you'd amazed how much you can do quickly and with little code. This may well be why such frameworks aren't really "obvious" for Python, unlike, say, Java.

Also, once you're done you'll have a better understanding of what to look for in another framework.

Will Hartung
I almost feel like I want to see another framework first so I can get an idea of how to make my own :)
goldenratio
+5  A: 

It sounds like web.py might suit you. Pylons and TurboGears aren't "application frameworks" at quite the same level of say Django, but they're certainly "full stack" frameworks, most useful for developing yes, web applications. But then, that's what mostly gets written.

Knowing what sort of things you're planning on doing might help people to guide you to the right sort of library.

womble
This looks great, thanks. I am only tinkering now, so while I will get to full-stack frameworks, right now a learning tool like web.py seems great. Simple so I can learn the in's-and-out's of python web development, I suppose.
goldenratio
+5  A: 

Right now the hottest "low level" framework is werkzeug and would be a very good place to start. It's minimal and WSGI compliant so you can easily plug-in a lot of the WSGI components out there like dozer for debugging memory leaks, etc.

If you need higher level try Pylons, which is still WSGI compliant, but gives you more stuff.

WSGI compliance is important for a few reasons, but most importantly so your app can run under mod_wsgi which totally rocks.

EDIT: I should note that almost all python frameworks, including Django, are WSGI compliant these days.

Van Gale
Werkzeug is sometimes called "anti-framework" and even creators call it "toolbox". Much like WebOb, but for me somewhat cleaner.
zgoda
A: 

"Django, Grok, Pylons and all these frameworks seem more like Application Frameworks, or CMS Frameworks"

First, I can't see what makes an "Application Framework" so unappealing. Perhaps you could update your question with some definitions that clarify your position.

Second, I can't see what makes Django or Pylons a "CMS Framework". Perhaps you could update your question with some definitions that clarify your position.

Django does pretty much everything you want.

S.Lott
+3  A: 

I somewhat answered your question here. But for a more complete list of HTTP frameworks:

  • CherryPy
  • web.py
  • Paste - only uses WSGI. Great for portability, but using hooks gets complicated the more you modify its behavior.
  • WebOb - simplified Paste. The API is probably a bit closer to CherryPy's.
Nikhil Chelliah
Thanks for the links. The other you post you made was very helpful as well!
goldenratio
A: 

Getting started with Django can be pretty easy too. Here's a 10-line single-file Django webapp:

import os
from django.conf.urls.defaults import patterns
from django.http import HttpResponse
filepath, extension = os.path.splitext(__file__)
ROOT_URLCONF = os.path.basename(filepath)

def yoohoo(request):
    return HttpResponse('Yoohoo!')

urlpatterns = patterns('', (r'^hello/$', yoohoo))

Check out my blog post Minimal Django for details.

olifante