[Grok-dev] JSON method/view name

Marc Rijken marc at rijken.org
Fri Oct 9 09:35:25 EDT 2009


I want to use 'getAccounts.json' in the url for a JSON view. Because the 
method name of a grok.JSON view class will be used as name of the json 
view and because a method name normally can not contain a dot, I had to 
make a work around. The work around is:

class JSONApi(grok.JSON):

     def getAccounts(self):
         return { "status": "ok"}

     getAccounts.__name__ = 'getAccounts.json'

setattr(JSONApi, 'getAccounts.json', JSONApi.getAccounts)

This work around works ok, but it looks uggly. Is this is preferred way 
to do so or do you have a better solution?



More information about the Grok-dev mailing list