I was thinking about using Django for one of my projects on GAE because it seems like a popular project and somewhat easy to use, but I’m not quite understanding yet why it’s better to have helper functions rather than controller/handler classes like Pylons or GAE’s normal WSGI handling has. With handler classes my controller might look like:
from google.appengine.ext.webapp import RequestHandler
class MainHandler(webapp.RequestHandler):
def get(self):
# Read data from BigTable here
self.response.out.write(outputhtml)
def post(self):
# Write data to BigTable here
#redirect back to the url
self.redirect(self.request.url)
Whereas the django helper function might look like:
from django.http import HttpResponse, HttpResponseRedirect
def mainview(request):
if request.method == 'POST':
# Write to BigTable Here
return HttpResponse(outputhtml)
elif request.method == 'GET':
# Read from BigTable Here
return HTTPResponseRedirect(request.url)
While the Django method might have the potential to have be a bit less verbose it feels like it would be harder to do things correctly, like factor code etc. I also don’t really like the conditional checks to see what kind of HTTP method was used. So either I would need to split GETs and POSTs to separate urls or just live with the conditional checks.
Personally I feel better with the Pylons-ish controller/handler approach. Anyone have an opinion?