user47741
user47741

Reputation: 3015

Is there a good way of automatically generating javascript client code from server side python

I basically want to be able to:

Example

python:

def hello_world():
    return "Hello world"

javascript:

...
<!-- This file is automatically generated (either dynamically or statically) -->
<script src="http://myurl.com/webservice/client_side_javascript"> </script> 
...
<script>
$('#button').click(function () {
     hello_world(function (data){ $('#label').text(data)))
}
</script>

A bit of research has shown me some approaches that come close to this:

But are there any approaches closer to what I want?

Upvotes: 5

Views: 5590

Answers (2)

user47741
user47741

Reputation: 3015

It looks like using a javascript XML RPC client (there is jquery plugin for this) together with an XML RPC server is a good way to go.

The jquery plugin will introspect your rpc service and will populate method names make it impossible to mis type the name of a method call without getting early warning. It will not however test the number of arguments that you pass, or their type.

There doesn't seem to be the same support for introspection on json rpc (or rather there doesn't seem to be a consistent standard). This approach can also be used with django.

I've put together some example code and uploaded it here (I hope that linking to one's blog posts isn't considered terrible form - a brief search of the internet didn't seem to suggest it was)...

Upvotes: 0

user177800
user177800

Reputation:

Yes there is, there is Pyjamas. Some people bill this as the "GWT for Python"

Upvotes: 6

Related Questions