[Grok-dev] Example JSON-RPC example

Souheil CHELFOUH trollfot at gmail.com
Fri Apr 3 05:34:40 EDT 2009


I think he wants to *receive* JSON datas, and that is his main problem

2009/4/3 Christian Klinger <cklinger at novareto.de>:
> Hi Roger,
>
> i don´t know if this is related to your problem.
> But the json tests in grok return always a dict
> back.
>
> class MammothView(grok.JSON):
>     grok.context(Mammoth)
>
>     def run(self):
>         return { 'me': 'grok' }
>
>     def another(self):
>         return { 'another': 'grok'}
>
> So maybe you have to say:
>
>    def reverse(self, msg):
>       return {'mystring': msg[::-1]}
>
>
> HTH Christian
>
>> on 04/02/2009 12:06 PM Souheil CHELFOUH wrote:
>>> A very simple example here :
>>> http://tracker.trollfot.org/browser/projects/dolmen/dolmen.packages/menhir.simple.navtree/menhir/simple/navtree/base.py
>>
>> Thanks Souheil,
>>
>> but I still have some problems understanding the JSON-RPC story. I
>> understand that methods in a JSON class result in views. That is, when
>> the method does not start with an underscore.
>>
>> But I don't really understand how to call/invoke/process the view.
>>
>> Let's say I followed the Grok Tutorial and have added this class to app.py:
>>
>> class SampleJson(grok.JSON):
>>     grok.context(Sample)
>>
>>     def reverse(self, msg):
>>         return msg[::-1]
>>
>> Then, after having created a sample application, when I enter the URL
>> http://localhost:8080/sample/reverse?msg=Hello
>>
>> the browser shows a page
>> "olleH"
>>
>> But shouldn't I be able to only receive this piece of data in
>> JSON-format and incorporate it into a web page? I don't get this piece
>> of the puzzle. It appears to involve requests that have the content type
>> application/x-www-form-urlencoded or application/json?
>>
>> I browsed a little around in your dolmen project, but I did not find how
>> your jsonrpc class is *used*.
>>
>> Background information: I am trying to see if pyjamas (www.pyjs.org) can
>> be used in conjunction with Grok. It is supposed to generate javascript
>> AJAX-widgets from python.
>>
>> I'd appreciate if someone could help me a little further on track.
>>
>> Best,
>>
>> Roger
>
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> http://mail.zope.org/mailman/listinfo/grok-dev
>


More information about the Grok-dev mailing list