django jsonrpc ajax,JSON-RPC

Simply see XML-RPC . Use the ​SimpleJSONRPCServer instead of SimpleXMLRPCServer and you are done!

You'll also want ​JSON RPC Client too.

$ cat testjsonrpc.py

import sys

import jsonrpclib

rpc_srv = jsonrpclib.ServerProxy("http://localhost:8000/json_rpc_srv/")

result = rpc_srv.multiply( int(sys.argv[1]), int(sys.argv[2]))

print "%d * %d = %d" % (int(sys.argv[1]), int(sys.argv[2]), result['result'])

There you go!

django-json-rpc

Another, easier to use JSON-RPC implementation.

Features:

Simple, pythonic API

Support for Django authentication

Mostly supports JSON-RPC 1.1 spec

Proxy to test your JSON Service

The basic API:

### myproj/myapp/views.py

from jsonrpc import jsonrpc_method

@jsonrpc_method('myapp.sayHello')

def whats_the_time(request, name='Lester'):

return "Hello %s" % name

@jsonrpc_method('myapp.gimmeThat', authenticated=True)

def something_special(request, secret_data):

return {'sauce': ['authenticated', 'sauce']}

### myproj/urls.py

from jsonrpc import jsonrpc_site

import myproj.myapp.views # you must import the views that need connected

urls += patterns('', (r'^json/', jsonrpc_site.dispatch))

To test your service:

>>> from jsonrpc.proxy import ServiceProxy

>>> s = ServiceProxy('http://localhost:8080/json/')

>>> s.myapp.sayHello('Sam')

{u'error': None, u'id': u'jsonrpc', u'result': u'Hello Sam'}

>>> s.myapp.gimmeThat('username', 'password', 'test data')

{u'error': None, u'id': u'jsonrpc', u'result': {u'sauce': [u'authenticated', u'sauce']}}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值