我正在使用 django_mongo_engine(0.4.0) 作为 django 应用程序的支持。
使用 like创建Instructor
对象
inst = Instructor.objects.create(
email=request.POST.get('email').lower(),
password = set_password(request.POST.get('password')),
title=request.POST.get('title'),
first_name=request.POST.get('first_name'),
last_name=request.POST.get('last_name'))
和
request.session['inst_id'] = inst.id
在 mongo shell 这个inst.id似乎是ObjectId(u'533c3b0c9b0dbb416e000000')
在调试模式下 (pdb)
Instructor.objects.all()[0].id
会给身份证 u'533c3b0c9b0dbb416e000000'
检索讲师对象时出现错误:
Instructor.objects.get(id=request.session['inst_id'])
ValueError: int() 以 10 为底的无效文字:'533c40a99b0dbb42d9000000'
instructor2 = Instructor.objects.get(id=ObjectId(request.session['inst_id']))
TypeError : int() 参数必须是字符串或数字,而不是“ObjectId”
instructor3 = Instructor.objects.get(id=str(request.session['inst_id']))
ValueError: int() 以 10 为底的无效文字:'533c40a99b0dbb42d9000000'
有什么线索吗?