简体   繁体   English

Hello world Pyamf 小错误信息

[英]Hello world Pyamf small error message

Hi i am trying to link flex to django with Pyamf嗨,我正在尝试使用 Pyamf 将 flex 链接到 django

As a first step i tried the basic Hello World http://pyamf.org/wiki/DjangoHowto作为第一步,我尝试了基本的 Hello World http://pyamf.org/wiki/DjangoHowto

But that results in an ErrorFault.但这会导致 ErrorFault。

I use django 1.0.2我使用 django 1.0.2

amfgateway.py in the root folder of my project (same level as settings) amfgateway.py在我的项目的根文件夹中(与设置相同的级别)

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在 urls.py

urlpatterns = patterns('',

    # test pyamf
    url(r'^gateway/', 'amfgateway.edoGateway'),
    ...
)

Then when i test the example with pyamf client然后当我用 pyamf 客户端测试示例时

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 '" ErrorFault level=error code=500 type=u'AttributeError' description=u"找不到路径 ['/gateway/myservice/echo'] 的视图,'DjangoGateway' object has no attribute 'name e '" Traceback: u “找不到路径 ['/gateway/myservice/echo'] 的视图,'DjangoGateway' object 没有属性 ' 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我认为您可能需要从 echo def 中取出请求参数,至少 pyamf 示例站点上的方法在方法中没有该参数

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.尽管错误无关,但 JMP 是正确的 - 您在网关上设置了expose_request=False ,并且 echo 的服务定义的第一个参数为 Django Http 请求 object。

This isn't going to work, however PyAMF does allow some granularity here, you can use the expose_request decorator, eg:这是行不通的,但是 PyAMF 在这里确实允许一些粒度,您可以使用 expose_request 装饰器,例如:

from pyamf.remoting.gateway import expose_request

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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