在Django中扩展自定义用户的用户表单

在Django中扩展自定义用户的用户表单

本文介绍了在Django中扩展自定义用户的用户表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我扩展了我的用户模型,如本SO发布中所述: 在Django中使用自定义字段扩展用户模型I extended my User Model as described in this SO Posting:Extending the User model with custom fields in Django但是,我正在尝试创建一个用户创建表单,但是我得到以下内容:However, I'm trying to create a User Create form but I get the following:'成员对象没有属性'set_password''Members' object has no attribute 'set_password'这是我的模型窗体:Here is my model form: c 的子类,因此您无法调用用户方法(如 set_password )。The method you chose to extend your User model is by creating a UserProfile (which you've called Member). A Member is not a subclass of User, so you can't call User methods (like set_password) on it.您的SignUpForm的Meta模型应该仍然是User,要获取扩展的UserProfile,您应该调用user.get_profile()。例如,要获取用户的性别,您可以调用 user.get_profile()。gender 。Instead, your SignUpForm's Meta model should still be User, and to get the extended UserProfile, you should call user.get_profile(). For instance, to get a user's gender, you would call user.get_profile().gender.阅读 https://docs.djangoproject.com/en / dev / topics / auth /#存储附加信息关于用户,以获取有关扩展用户配置文件的更多信息。Read https://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users for more information about extending the user profile. 这篇关于在Django中扩展自定义用户的用户表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-26 16:23