当前位置: 首页>>代码示例>>Python>>正文


Python UserProfile.gender方法代码示例

本文整理汇总了Python中accounts.models.UserProfile.gender方法的典型用法代码示例。如果您正苦于以下问题:Python UserProfile.gender方法的具体用法?Python UserProfile.gender怎么用?Python UserProfile.gender使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在accounts.models.UserProfile的用法示例。


在下文中一共展示了UserProfile.gender方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: signup

# 需要导入模块: from accounts.models import UserProfile [as 别名]
# 或者: from accounts.models.UserProfile import gender [as 别名]
def signup(request):
	context = {}
	context['title'] = _('Register')
	user = User()
	if request.user.is_authenticated():
		return redirect('accounts_accounts')
	userProfile = UserProfile()
	if request.method == 'POST':
		userForm = UserForm(request.POST, instance=user)
		userProfileForm = UserProfileForm(request.POST, instance=userProfile)
		if userForm.is_valid() and userProfileForm.is_valid():
			userData = userForm.cleaned_data
			user.username = userData['username']
			user.first_name = userData['first_name']
			user.last_name = userData['last_name']
			user.email = userData['email']
			user.set_password(userData['password'])
			user.save()

			userProfile = user.get_profile()
			userProfileData = userProfileForm.cleaned_data
			userProfile.gender = userProfileData['gender']
			userProfile.birthday = userProfileData['birthday']
			userProfile.save()

			user = authenticate(username=userData['username'], password=userData['password'])
			login(request, user)
			return redirect('accounts_accounts')
	else:
		userForm = UserForm(instance=user)
		userProfileForm = UserProfileForm(instance=userProfile)
	context['userForm'] = userForm
	context['userProfileForm'] = userProfileForm
	return render_to_response('accounts/register.html', context, context_instance=RequestContext(request))
开发者ID:qij3,项目名称:django-accounts,代码行数:36,代码来源:views.py

示例2: signup

# 需要导入模块: from accounts.models import UserProfile [as 别名]
# 或者: from accounts.models.UserProfile import gender [as 别名]
def signup(request):
    if request.method == "POST":
        form = UserEmailCreationForm(request.POST)
        try:
            User.objects.get(email=request.POST['email'])
            return render(request, 'registration/signup.html', {
                'form': form,
                'error': "Already Exist Email address!"
            })
        except ObjectDoesNotExist:
            if form.is_valid():
                user = form.save()
                user_profile = UserProfile()
                user_profile.user = user
                user_profile.gender = request.POST['gender']
                user_profile.save()
                return redirect('login')
    else:
        form = UserEmailCreationForm()

    return render(request, 'registration/signup.html', {'form': form})
开发者ID:UrangUrang,项目名称:Guide,代码行数:23,代码来源:views.py


注:本文中的accounts.models.UserProfile.gender方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。