gpt4 book ai didi

python - Flask 的 UserMixin 在 Django 中的等价物是什么?

转载 作者:太空宇宙 更新时间:2023-11-03 16:29:34 24 4
gpt4 key购买 nike

在 Flask 中,有来自 flask-login 模块的 flask.ext.login.UserMixin

我尝试寻找 Django 的等价物,与 Flask 的 UserMixin 最接近的是来自的 django.contrib.auth.models.User https://docs.djangoproject.com/en/1.9/ref/contrib/auth/

Django 相当于 Flask 的 UserMixin 吗?有什么区别?

PyBossa, using Flask's UserMixin ,他们继承自 UserMixin 以添加 twitter/facebook oauth,可以继承 django.contrib.auth.models.User 并对其进行子类化以执行相同的操作吗?

最佳答案

确实如此。它是一个存储有关登录用户的信息的模型。同样的事情。

您可以扩展模型或完全替换它。

There are two ways to extend the default User model without substituting your own model. If the changes you need are purely behavioral, and don’t require any change to what is stored in the database, you can create a proxy model based on User. This allows for any of the features offered by proxy models including default ordering, custom managers, or custom model methods.

扩展模型:
https://docs.djangoproject.com/en/1.9/topics/auth/customizing/#extending-the-existing-user-model

替换用户模型:
https://docs.djangoproject.com/en/1.9/topics/auth/customizing/#substituting-a-custom-user-model

关于python - Flask 的 UserMixin 在 Django 中的等价物是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37715517/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com