Hello world Pyamf 小错误消息
你好,我正在尝试使用 Pyamf 将 flex 链接到 django
作为第一步,我尝试了基本的 Hello World http://pyamf.org/wiki/DjangoHowto
但这会导致 ErrorFault。
使用 django 1.0.2
我在项目的根文件夹中
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)
amfgateway.py (与设置相同的级别) 在 urls.py
urlpatterns = patterns('',
# test pyamf
url(r'^gateway/', 'amfgateway.edoGateway'),
...
)
然后当我使用 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!')
<强>我明白
ErrorFault level=error code=500 type=u'AttributeError'description=u"找不到视图 对于路径 ['/gateway/myservice/echo'],'DjangoGateway' 对象没有属性 'nam e'" 追溯: u“找不到路径 ['/gateway/myservice/echo'] 的视图,'DjangoGateway' 对象 ha 没有属性“名称””
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'"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您可能需要从 echo def 中取出请求参数,至少 pyamf 示例站点上的方法在方法中没有该参数
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
尽管错误无关,但 JMP 是正确的 - 网关上有
expose_request=False
,并且 echo 的服务定义将第一个参数作为 Django Http 请求对象。这是行不通的,但是 PyAMF 确实允许这里有一些粒度,您可以使用 Exposure_request 装饰器,例如:
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.: