Hi i am trying to link flex to django with Pyamf
As a first step i tried the basic Hello World http://pyamf.org/wiki/DjangoHowto
But that results in an ErrorFault.
I use django 1.0.2
amfgateway.py in the root folder of my project (same level as settings)
import pyamf
from pyamf.remoting.gateway.django import DjangoGateway
from django.contrib.auth.models import User
pyamf.register_class(User, 'django.contrib.auth.models.User')
def get_users(requet):
return User.objects.all()
def echo(request, data):
return data
services = {
'myservice.echo': echo,
'myservice.get_users': get_users,
}
edoGateway = DjangoGateway(services, expose_request=False)
In urls.py
urlpatterns = patterns('',
# test pyamf
url(r'^gateway/', 'amfgateway.edoGateway'),
...
)
Then when i test the example with pyamf client
from pyamf.remoting.client import RemotingService
gw = RemotingService('http://127.0.0.1:8000/gateway/')
service = gw.getService('myservice')
print service.echo('Hello World!')
I get
ErrorFault level=error code=500 type=u'AttributeError' description=u"Cannot find a view for the path ['/gateway/myservice/echo'], 'DjangoGateway' object has no attribute 'nam e'" Traceback: u"Cannot find a view for the path ['/gateway/myservice/echo'], 'DjangoGateway' object ha s no attribute 'name'"
Although the error is unrelated, JMP is correct - you have
expose_request=False
on the gateway and the service definition for echo has the first argument as the Django Http request object.This isn't going to work, however PyAMF does allow some granularity here, you can use the expose_request decorator, e.g.: