本文整理汇总了Python中accounts.models.User.username方法的典型用法代码示例。如果您正苦于以下问题:Python User.username方法的具体用法?Python User.username怎么用?Python User.username使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类accounts.models.User
的用法示例。
在下文中一共展示了User.username方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_duplicate_email_check
# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import username [as 别名]
def test_duplicate_email_check(self):
user = User()
user.username = "test"
user.email = "[email protected]"
user.set_password("test")
user.full_clean()
user.save()
with self.assertRaises(ValidationError):
user2 = User()
user2.username = "test2"
user2.email = "[email protected]"
user2.set_password("test")
user2.full_clean()
user2.save()
示例2: authenticate
# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import username [as 别名]
def authenticate(self, token):
response_profile = requests.get(
'https://graph.facebook.com/me/',
params={
'access_token': token,
}
)
facebook_profile = response_profile.json()
if 'error' in facebook_profile:
return None
try:
user = User.objects.get(facebook_id=facebook_profile.get('id'))
except User.DoesNotExist:
user = User(facebook_id=facebook_profile.get('id'))
if facebook_profile.get('id') in settings.FACEBOOK_ADMINS:
user.is_staff = True
user.is_superuser = True
user.username = facebook_profile.get('id')
user.set_unusable_password()
user.facebook_access_token = token
user.email = facebook_profile.get('email', '')
user.first_name = facebook_profile.get('first_name')
user.last_name = facebook_profile.get('last_name')
user.save()
return user
示例3: create_user
# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import username [as 别名]
def create_user(username=None, email=None, password=None):
u = User()
u.username = username
u.email = email
u.set_password(password)
u.save()
return True
示例4: create_user
# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import username [as 别名]
def create_user():
user = User()
user.username = request.form.get('username', None)
user.first_name = request.form.get('first_name', '')
user.last_name = request.form.get('last_name', '')
user.email = request.form.get('email', '')
user.account = request.form.get('account', None)
user.set_password(request.form.get('password', ''))
user.save()
return redirect(url_for('accounts.users'))
示例5: test_creating_new_user
# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import username [as 别名]
def test_creating_new_user(self):
user = User()
user.username = "test"
user.email = "[email protected]"
user.set_password("test")
user.full_clean()
user.save()
all_users = User.objects.all()
self.assertEqual(len(all_users), 1)
user_from_database = all_users[0]
self.assertEquals(user_from_database, user)