使用django轻松处理jsonrpc和xmlrpc请求
rpc4django的Python项目详细描述
安装
pip install rpc4django[reST]
配置
首先,需要将新的url模式添加到根文件urls.py中。 你可以用任何你喜欢的东西替换r'^RPC2$'
# urls.py from rpc4django.views import serve_rpc_request urlpatterns = ( # rpc4django will need to be in your Python path url(r'^RPC2$', serve_rpc_request), )
其次,将rpc4django添加到 settings.py。
# settings.py INSTALLED_APPS = ( 'rpc4django', )
最后,您需要让rpc4django知道要提供哪些方法。 RPC4Django递归地导入^{tt4}中的所有应用程序$ 并使用 @rpcmethoddecorator可用作rpc方法。你总是能写 您的RPC方法在另一个模块中,只需将其导入__init__.py
# testapp/__init__.py from rpc4django import rpcmethod # The doc string supports reST if docutils is installed @rpcmethod(name='mynamespace.add', signature=['int', 'int', 'int']) def add(a, b): '''Adds two numbers together >>> add(1, 2) 3 ''' return a+b