Archive for the 'flex' Category

Django AMF service

I made a in Jaiku a few days ago that said the following,

Django amf service, once installed is a beauty to behold

Well the key part for me was “once installed”. I’ll attempt to explain how I got it working here.

is a middleware service for Django that allows you create AMF web services. Action Message Format is the web services format typically used by Flex applications by using the . Being able to support remoting web services in Django goes a long way to being able to integrate Flex applications with Django.

Download Django AMF from and install to your site-packages using Then add ‘amf.django.middleware.AMFMiddleware’ to the MIDDLEWARE_CLASSES list in your settings. The key thing now is that you need to add the following to your settings,

AMF_GATEWAY_PATH = '/gateway/'
AMF_LOG_FILE = 'log/amf.txt'

AMF_GATEWAY_PATH tells django that anything accessed under this path is an AMF service and gets passed into the middleware. e.g. my contains

(r'^/gateway/flashtest/test', 'my_app.views.flashtest'),

and that’s it!

I’m using the in Flex to talk to this service as follows:

var service:RemoteService = new RemoteService();
service.gatewayUrl = "http://localhost:8000/gateway/"
service.destination = "flashtest"
var token:AsyncToken = service.test(test_variable1, test_variable2);

Note that I’ve left the result handlers and assignment of the variables out for brevity, but hopefully you get the picture. The function flashtest gets called and the Flex data types get mapped to python data types as described .

It’s simplicity in design really is beautiful to behold.