简体   繁体   English

将带有Pyamf的Django对象返回Flex时出现500错误

[英]500 error when returning Django object with Pyamf to Flex

I'm able to return django models that have only CharFields/Dates/Integers, but now I'm trying to return models that have ForeignKey properties and I'm getting this error in Flex in my NetStatusEvent.NET_STATUS onError event handler: 我能够返回只有CharFields / Dates / Integers的Django模型,但是现在我试图返回具有ForeignKey属性的模型,并且在NetStatusEvent.NET_STATUS onError事件处理程序的Flex中遇到此错误:

m_info  Object (@16491fe9)  
code    "NetConnection.Call.Failed" 
description "HTTP: Status 500"  
details "http://127.0.0.1:8000/gateway/"    
level   "error" 

Here are the models that matter in models.py: 以下是models.py中重要的模型:

class RewardActBase(models.Model):
    user = models.ForeignKey(User)
    start_date = models.DateTimeField(blank=True, null=True)
    progress_value = models.IntegerField(default=0)
    coupon_act = models.ForeignKey(CouponAct)

    class Meta:
        abstract = True


class ChallengeAct(RewardActBase):
    challenge = models.ForeignKey(Challenge)

    def __unicode__(self):
        return self.challenge.title'

class CouponAct(models.Model):
    coupon = models.ForeignKey(Coupon)
    earned_date = models.DateTimeField(blank=True, null=True)
    redeemed_date = models.DateTimeField(blank=True, null=True)
    expiration_date = models.DateTimeField(blank=True, null=True)

    def __unicode__(self):
        return self.coupon.title

Then when I want to get retrieve these object via pyamf, this is the method I'm using, which is giving me the error I listed above: 然后,当我想通过pyamf检索这些对象时,这就是我正在使用的方法,这给了我上面列出的错误:

@login_required
def get_challenge_act(http_request, location_id):
    user = http_request.user

    c = ChallengeAct();
    c.challenge = Challenge.objects.select_related().get(id=1)
    c.start_date = datetime.now()
    c.progress_value = 1
    c.user = user
    new_coupon_act = CouponAct()
    new_coupon_act.coupon = Coupon.objects.select_related().get(id=c.challenge.coupon.id)
    new_coupon_act.earned_date = datetime.now()
    new_coupon_act.save()
    c.coupon_act = new_coupon_act
    c.save()

    return c

The interesting thing is that if I change my get_challenge_act method to return a property of the ChallengeAct object, I don't get the error. 有趣的是,如果更改get_challenge_act方法以返回ChallengeAct对象的属性,则不会收到错误。 So I can return properties or objects that belong to the ChallengeAct, but not the ChallengeAct itself. 因此,我可以返回属于ChallengeAct的属性或对象,但不能返回ChallengeAct本身的属性或对象。 For example, the following code returns a Challenge object with no errors: 例如,以下代码返回没有错误的Challenge对象:

    return c.challenge

So it appears that there is some problem returning a Django model with foreginkey models as properties? 如此看来,返回以foreginkey模型作为属性的Django模型有一些问题吗? Am I doing something wrong? 难道我做错了什么?

By process of elimination, I found that it was the User object on the ChallengeAct that was causing the problem, and I got the ambiguous 500 error to go away by setting the user object to None after saving and right before returning. 通过消除过程,我发现是引起问题的原因是ChallengeAct上的User对象,通过将用户对象保存后设置为None,并在返回之前将其设置为None,我消除了模棱两可的500错误。

@login_required
def get_challenge_act(http_request, location_id):
user = http_request.user

c = ChallengeAct();
c.challenge = Challenge.objects.select_related().get(id=1)
c.start_date = datetime.now()
c.progress_value = 1
c.user = user
new_coupon_act = CouponAct()
new_coupon_act.coupon = Coupon.objects.select_related().get(id=c.challenge.coupon.id)
new_coupon_act.earned_date = datetime.now()
new_coupon_act.save()
c.coupon_act = new_coupon_act
c.save()
c.user = None

return c

I'd love to hear why that happened though. 我很想听听为什么会这样。 Anyone have any ideas? 有人有想法么?

--update-- I found that I can see what the actual 500 error is by looking at the terminal log, after running my runserver command. --update--运行runserver命令后,通过查看终端日志,我发现实际的500错误是什么。 So the actual error was: 因此,实际错误是:

Could not import "cpyamf.amf3": Disallowed C-extension or built-in module

I'm not sure what that is, or why I get it only when trying to include user object on my return result, but for now I can just not include the user object to avoid the error. 我不确定这是什么,或者为什么我只在尝试在返回结果中包括用户对象时才得到它,但是现在我不能只包含用户对象以避免错误。

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

相关问题 使用pyAMF在Django中从Flex进行身份验证 - authenticate from Flex in Django with pyAMF PyAMF DatabaseError:“数据库不支持此查询。” 返回User对象时 - PyAMF DatabaseError: 'This query is not supported by the database.' when returning the User object PyAMF / Django-Flex类映射错误 - PyAMF / Django - Flex class mapping errors 如何在Django / PyAMF和Flex之间映射字段名称? - How can I map field names between Django/PyAMF and Flex? 在Django中返回响应时出现意外错误500,这是怎么回事? - Unexpected error 500 when returning response in Django, what's going on? Django + pyamf:从动作脚本应用程序调用网关时出现奇怪的异常 - Django + pyamf: Strange exception when calling the gateway from actionscript application django POST返回内部服务器500错误 - django POST returning Internal Server 500 error Django 返回 500 Internal Server Error 而不是 index.html 当 Debug = False - Django returning 500 Internal Server Error instead of index.html when Debug = False 在Django中的Ajax调用后返回单个json对象时出错 - Error when returning single json object after an ajax call in django 在 django rest 框架中返回 Respose object 时出现 NoReverseMatch 错误 - NoReverseMatch error when returning Respose object in django rest framework
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM