سؤال

i want to create a simple Django(1.3) project that uses JSON-RPC. i use this implementation:

django-json-rpc

and this is my project files:

urls.py:

from django.conf.urls.defaults import patterns, include, url
from myapp.views import *
from jsonrpc import jsonrpc_site

 urlpatterns = patterns('',
                   url(r'^json/browse/', 'jsonrpc.views.browse', name="jsonrpc_browser"),
                   url(r'^json/', jsonrpc_site.dispatch, name="jsonrpc_mountpoint"),
                   (r'^json/(?P<method>[a-zA-Z0-9.]+)$', jsonrpc_site.dispatch),
 )

views.py:

from jsonrpc import jsonrpc_method

@jsonrpc_method('sayHello')
def hello(request, name='Lester'):
   return "Hello %s" % name

when i test this code in JSON-RPC Browser(included with the library) it doesn't work. whe is want to add this import in the shell:

from jsonrpc.proxy import ServiceProxy

i get the response like this:

Error:

what's the problem here? it seems a simple process but it doesn't work for me.

هل كانت مفيدة؟

المحلول

i found the solution. in fact json-rpc works but in JSON-RPC Browser i have to treat with some difference than regular way. according to here, we should initialize and call json-rpc methods like this:

from jsonrpc.proxy import ServiceProxy
s = ServiceProxy('http://localhost:8080/json/')
s.myapp.sayHello('Sam')

but it's not true! this method is correct when we use it in django shell or in our main code! in JSON-RPC Browser we just need to call our method like this:

jsonrpc.sayHello('sam')

just that!

thanks to all.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top