在MongoDB中使用内置Django认证/用户模型
我正在从sqlite切换到MongoDB,并且按照Django MongoDB Engine的设置和配置步骤进行了操作。现在,当我在views.py中的adduser方法里返回一个HTTP响应来添加用户时:
def adduser(request):
username = request.POST['username']
password = request.POST['password']
u = User.objects.create_user(username, request.POST['email'], password)
u.save()
a = Accounts(user=u)
p = Passwords(user=u)
a.save()
p.save()
user = authenticate(username=username, password=password)
if user is not None and user.is_active:
auth.login(request, user)
return HttpResponseRedirect("/%s/" %u.id)
else:
return HttpResponseRedirect("/account/invalid/")
我遇到了这个错误:
DatabaseError at /adduser
relation "auth_user" does not exist
显然,关系不存在是因为MongoDB是NoSQL数据库。请问这个认证系统不支持吗?或者Mongo-engine有没有更好的解决方案?也许我应该直接换成Postgre?(因为sqlite无法处理同时多个用户,所以不太适合)
我看到过这个问题,但那是去年问的,希望现在情况有所改变,因为MongoDB今年变得非常流行。