使用内置的 Django 身份验证/用户模型与 Mongodb

发布于 2024-12-13 16:13:07 字数 1072 浏览 0 评论 0原文

从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无所谓啦 2024-12-20 16:13:07

MongoEngine 使用 MongoDB 为 Django 应用程序提供身份验证。

MongoEngine provides authentication for Django apps with MongoDB.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文