模型.py
class User(EmbeddedDocument,Document):
''' Store user's info'''
user_id = IntField(unique = True)
user_name = StringField(unique =True,primary_key =True,max_length = 256)
user_secret = StringField(max_length=256)
视图.py
def register(request):
accept = False
un = request.REQUEST.get('username')
ps = request.REQUEST.get('password')
if not un:
raise ValueError('The given username must be set')
if not ps:
raise ValueError('The given password must be set')
if isUserExistByName(un):
o='The name has been registered.'
raise TAUTHException(o)
else:
uid = getNextCount(UserCount)
ps_hash = password_hash(un,ps)
user = User(user_id = uid,user_name = un,user_secret = ps_hash)
user.save(cascade = True)
accept = True
result = {'accept':accept}
msg = urlencode(result)
return HttpResponse(msg)
当我尝试注册用户时,程序运行良好,但 mongodb 不存储该用户。奇怪的是,如果我将用户更改为
class User(Document):
''' Store user's info'''
user_id = IntField(unique = True)
user_name = StringField(unique =True,primary_key =True,max_length = 256)
user_secret = StringField(max_length=256)
它运行良好,mongodb 存储用户成功。