对象不可脚本化意味着什么? [英] What does it mean for an object to be unscriptable?
本文介绍了对象不可脚本化意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不知道这里发生了什么...我只想检查模型字段的值,然后相应地更新它...任何帮助或见解表示赞赏!
I don't know what's going on here... I just want to check the value of a model field and then update it accordingly... any help or insight is appreciated!
型号:
class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
beta = models.CharField(max_length=1, blank=True, null=True)
查看:
from internal.accounts.models import UserProfile
from django.contrib.auth.models import User
@login_required
def beta_testers(request):
user = User.objects.get(username=request.user.username)
user_profile = user.get_profile()
count = UserProfile.objects.filter(beta='1').count()
if count < 50 and not user_profile['beta']:
user_profile['beta'] = '1'
user_profile.save()
错误:
TypeError at /utilities/beta-signup/
'UserProfile' object is unsubscriptable
Request Method: GET
Request URL: http://localhost/utilities/beta-signup/?x=1&y=15
Django Version: 1.2.1
Exception Type: TypeError
Exception Value:
'UserProfile' object is unsubscriptable
Exception Location: C:/djangointernalcms_helperviews.py in beta_testers, line 284
推荐答案
错误是unSUBscriptable".您的 user_profile 对象不是字典.使用 user_profile.beta
,而不是 user_profile['beta']
.
The error is "unSUBscriptable". Your user_profile object isn't a dictionary. Use user_profile.beta
, not user_profile['beta']
.
这篇关于对象不可脚本化意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文