简体   繁体   中英

Hello world Pyamf small error message

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 '"

I think you may need to take the request parameter out of your echo def, at least the method on the pyamf example site doesn't have that parameter in the method

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, eg:

from pyamf.remoting.gateway import expose_request

@expose_request
def echo(request, data):
    return echo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM