使用内置的 Django 身份验证/用户模型与 Mongodb
从 sqlite 切换到 MongoDB,我遵循了 Django MongoDB 引擎。现在,当我通过从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/")
这是我得到的错误: /adduser 处的数据库错误 关系“auth_user”不存在
自然,自 MongoDB NoSQL 以来,该关系就不存在。是不支持auth系统还是Mongo-engine有更好的解决方案?也许我应该搬到 Postgre? (sqlite 无法处理并发用户,因此不是一个可行的选择)
我看到 this 问题,但那是一年前,希望到那时情况会有所改变,因为 MongoDB 今年已经非常受欢迎。
Switching over from sqlite to MongoDB and I followed all of the setup/configuration settings for Django MongoDB Engine. Now when I go to add a user by returning an HTTP response from to the adduser method in views.py:
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/")
This is the error I get:DatabaseError at /adduser
relation "auth_user" does not exist
Naturally the relationship doesn't exist since MongoDB NoSQL. Is the auth system not supported or does Mongo-engine have a better solution? Perhaps I should just move to Postgre? (sqlite cannot handle the simultaneous users so isn't a viable option)
I saw this question but that was a year ago so hopefully things have changed by then as MongoDB has gained a lot of popularity this year.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MongoEngine 使用 MongoDB 为 Django 应用程序提供身份验证。
MongoEngine provides authentication for Django apps with MongoDB.