Hoa*_*ham 5 python google-app-engine
我想问一下它是什么意思"AttributeError:'unicode'对象没有属性'has_key'"这是完整的堆栈跟踪:
Traceback (most recent call last):
File "D:\Projects\GoogleAppEngine\google_appengine\google\appengine\ext\webapp\__init__.py", line 509, in __call__
handler.post(*groups)
File "D:\Projects\workspace\foo\src\homepage.py", line 71, in post
country=postedcountry
File "D:\Projects\GoogleAppEngine\google_appengine\google\appengine\ext\db\__init__.py", line 656, in __init__
prop.__set__(self, value)
File "D:\Projects\GoogleAppEngine\google_appengine\google\appengine\ext\db\__init__.py", line 2712, in __set__
value = self.validate(value)
File "D:\Projects\GoogleAppEngine\google_appengine\google\appengine\ext\db\__init__.py", line 2742, in validate
if value is not None and not value.has_key():
AttributeError: 'unicode' object has no attribute 'has_key'
Run Code Online (Sandbox Code Playgroud)
让我来描述一下这种情况:
首先,我创建了models.py,其中包含用于CMSRequest的db.Model,其具有引用CMSCountry类的属性country
class CMSRequest(db.Model):
country = db.ReferenceProperty(CMSCountry, required=True)
class CMSCountry(db.Model):
name = db.StringProperty(required=True)
Run Code Online (Sandbox Code Playgroud)然后,我创建了一个bulkloader类来将数据导入CMSCountry
在表单中,用户可以从下拉列表框中选择国家/地区,结果将被回发并保存到CMSRequest对象
def post(self):
postedcountry = self.request.get('country')
cmsRequest = models.CMSRequest(postedcountry)
Run Code Online (Sandbox Code Playgroud)也许我找到了我的问题的解决方案,这是因为我还没有将CMSCountry的已发布密钥转换回CMSRequest.
谢谢大家!
在这一行:
if value is not None and not value.has_key():
Run Code Online (Sandbox Code Playgroud)
value是一个unicode字符串.看起来代码期待它是一个db.Model,
(从我所看到的,has_key是一种方法db.Model,以及Python字典的方法,但这必须是db.Model一个,因为它是在没有参数的情况下调用的.)
您是否将字符串传递给期望db.Model?的GAE API ?
| 归档时间: |
|
| 查看次数: |
43158 次 |
| 最近记录: |