1

我有一个个人资料课程:

class profile(db.Model):
  user = db.stringProperty()
  # Other properties ...
  access = db.ListProperty(db.keys)

class apps(db.Model):
  name = db.StringProperty()

配置文件类在那里安静了一段时间,但我们最近添加了访问字段,它将存储应用程序的密钥。现在我们在应用程序上添加配置文件权限,访问字段不会在模型中更新。

这在本地主机上完全可以正常工作,但是当我在服务器上更新它时,我得到这个错误“'NoneType'对象没有属性'access'”有没有人遇到过同样的情况

更新: 发现配置文件类中的一个对象被返回为无。这是在本地主机上获取配置文件对象但在服务器上没有的代码

 liuser = users.User(request.POST['user']) 
 #request.POST['user'] gets user Gmail ID, which is being converted to user object
 profiles=Profile.all().filter(" user =", liuser).get()
 userprofile=profiles

 #tried below code which returns "'NoneType' object has no attribute 'access'" on server, the same gets a profile object on localhost
 if not hasattr(userprofile, "access"): 
    userprofile.access=[]

@Robert希望格式现在很好。

谢谢你赛克里希纳

4

2 回答 2

1

我们能够解决这个问题。问题出在 users.User 对象上,该对象不为 gmail 用户附加 @gmail.com,但它接受具有域名的其他域,但抛出 None 类型对象

再次感谢您的帮助

于 2010-11-18T09:04:12.397 回答
0

将属性添加到模型时,数据存储中的模型的现有实例不会自动获取该属性。

您将需要修改与配置文件实体交互的处理程序代码以检查是否存在访问权限。Python 的hasattr函数就可以了。像这样的东西:

a_profile = profile.all().somequerystuffheretogetaninstance().get()
if a_profile is not None:
    if not hasattr(a_profile, "access"):
        a_profile.access = whateveryourdefaultdatais
    # perform my data logic normally after this, but remember to persist
    # this to the datastore to save the new access property.
于 2010-11-16T19:36:35.610 回答