如何在Django中一起使用CustomUser模型和OpenID进行身份验证?
我正在学习Python Django 框架。感谢 StackOverFlow 社区,我学会了如何在 django 中使用 open-id (我正在使用的 Social_auth )。
使用social_auth,登录和注销过程非常简单实用。但我想在用户之间建立友谊关系,为此我创建了新的模型类,该模型类是从 from django.contrib.auth.models import User
扩展的,并在 auth_table 中创建新用户时添加控制,我在 CustomUser 表上创建新用户。(效率不高,因为来自 open-id 的参数对于每个 open-id 连接都不同) 我的模型代码在这里
from datetime import datetime
from django.core.exceptions import ObjectDoesNotExist
from django.db import models
from django.contrib.auth.models import User
from django.contrib.auth.models import UserManager
# Create your models here.
class CustomUser(User):
gender = models.CharField(max_length=50)
location = models.CharField(max_length=50)
bio = models.CharField(max_length=50)
web_pages = models.CharField(max_length=50)
friends = models.ManyToManyField("self")
我如何在 Django 中一起使用 CustomUser 模型和 OpenID 进行身份验证?
任何帮助将不胜感激。
I'm learning Python Django framework. Thanks to StackOverFlow Community, i have learned how to use open-id in django (social_auth i'm using ).
with social_auth, sign in and sign out process are pretty easy and practical. But i want to build friendship relationship between users, for this i created new model class which is extended from from django.contrib.auth.models import User
and add control when new user is created in auth_table, i create new user on CustomUser Table.(It is not efficient because the parameters coming from open-id are different for each open-id connection)
My model code is here
from datetime import datetime
from django.core.exceptions import ObjectDoesNotExist
from django.db import models
from django.contrib.auth.models import User
from django.contrib.auth.models import UserManager
# Create your models here.
class CustomUser(User):
gender = models.CharField(max_length=50)
location = models.CharField(max_length=50)
bio = models.CharField(max_length=50)
web_pages = models.CharField(max_length=50)
friends = models.ManyToManyField("self")
And How can i use CustomUser model and OpenID together in Django for authentication?
Any Help will be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Django 中扩展 User 类的方法是提供用户配置文件类。请参阅此处。然后,您可以像往常一样使用用户模型并按需获取配置文件实例。
The way to extend the User class in Django is to provide user profile class. See here. You can then just use the User model as always and get the profile instance on demand.