XML RPC Server Howto - release-engineering/kobo GitHub Wiki
In this example, '''rpcserver''' project name is used, but feel free to use different name, especially if you don't want to conflict with other projects based on this example :)
$ django-admin.py startproject rpcserver
$ cd rpcserver $ mkdir xmlrpc $ touch xmlrpc/__init__.py
We'll work with test.py in this exampleBR First argument of each method must be 'request' - it contains Django request object with session and user informationBR Add each method to _ _all_ _ listBR
# import various decorators, the most important are: # - login_required # - admin_required # - user_passes_test from kobo.django.xmlrpc.decorators import * # list of all exported methods __all__ = ( "logged_user", ) @login_required def logged_user(request): """help text displayed on help page""" return str(request.user)
update urls.py
urlpatterns = patterns("" ... url(r"^xmlrpc/", include("rpcserver.xmlrpc.urls")), ... )
create xmlrpc/urls.py
from django.conf.urls.defaults import * urlpatterns = patterns("", # handlers in kobo.django.xmlrpc.views are generated according project settings url(r"^client/", "kobo.django.xmlrpc.views.client_handler", name="xmlrpc/client"), #url(r"^worker/", "kobo.django.xmlrpc.views.worker_handler", name="xmlrpc/worker"), )
XMLRPC_METHODS = { "client": ( # include all auth and client methods from kobo # second argument means a method name prefix (kobo.hub.xmlrpc.auth.login -> auth.login) # note: if you use kobo.hub, register kobo.hub.xmlrpc.auth instead ("kobo.django.xmlrpc.auth", "auth"), # register all methods in the test module, use 'test' prefix ("rpcserver.xmlrpc.test", "test"), # only one method can be registered: #("rpcserver.xmlrpc.test.logged_user", "some_random_prefix.and_name"), ), # multiple handlers can be specified: # "worker": ( # ... # ), }