2008-7-2

flex与django/python通信,通过pyamf

2009注:中文howto发布时,应当是低版本pyamf,所以没有加destination。详见下文

-----------------------------------

pyamf官网上推荐了一篇中文howto12),介绍django与flex通信,通过pyamf(一个python的开源api,专门针对amf协议)。其中有个小问题,就是destination的设置。

共有三处会用到该属性(这篇中文howto只提到了两处),我的代码片段如下:

1 flex:<mx:RemoteObject

id="djangoService" destination="destinationFucker" showBusyCursor="true"/>


2 services-config.xml:  <destination id="destinationFucker">

<channels> <channel ref="fuckChannel"/> </channels> </destination>


3 amfgateway.py:usersGateway = DjangoGateway({

'destinationFucker.testFuck':testFuck, 'destinationFucker.testArrayFuck':testArrayFuck })


深红色的python部分,在原文中是没有destination的(当然原文中也没有fu*k)。 我不知道原文的example是如何测试的,至少我滴环境下(django自带server,无数据库)如果在python(或django)的方法前不加destination(即直接'testArrayFuck':testArrayFuck ),flex是无法找到远程方法testArrayFuck的。

flex的RemoteObject,天生出来是与java后台相亲相爱的 ,在java中,destination对应的可以是该class名,即:

class destinationFucker
{
public function testArrayFuck(){}
}


而在python中,至少这个example中米有class,所以必须在映射方法testArrayFuck时加上destination才能找到“destinationFucker.testArrayFuck”。

那么客户端flex及services-config中不写destination行不行涅?
答案貌似是“不行”,如果在RemoteObject及services-config中去掉destination,运行时会找不到destination而报错。

那么客户端flex及services-config中destination id=""行不行涅?
答案也貌似是“不行”,在services-config中destination的id不接受""。至少在flex默认配置下这样是不行滴。

另外,上边举的那个java的例子,其实我猜的,因为从没用java试过 ^_<

0 评论: