本文整理汇总了Python中userprofile.models.UserProfile.firstname方法的典型用法代码示例。如果您正苦于以下问题:Python UserProfile.firstname方法的具体用法?Python UserProfile.firstname怎么用?Python UserProfile.firstname使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类userprofile.models.UserProfile
的用法示例。
在下文中一共展示了UserProfile.firstname方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit
# 需要导入模块: from userprofile.models import UserProfile [as 别名]
# 或者: from userprofile.models.UserProfile import firstname [as 别名]
def edit(request):
if request.method == 'POST': # If the form has been submitted...
form = UserProfileForm(request.POST) # A form bound to the POST data
if form.is_valid():
userprofile = UserProfile()
userprofile.user = request.user
userprofile.firstname = form.cleaned_data['firstname']
userprofile.lastname = form.cleaned_data['lastname']
userprofile.number = form.cleaned_data['number']
userprofile.serie = form.cleaned_data['serie']
userprofile.sexe = form.cleaned_data['sexe']
userprofile.phoneNumber = form.cleaned_data['phoneNumber']
userprofile.save()
return redirect('userprofile.views.display') # Redirect after POST
else:
return render(request,
'userprofile/userprofile_edit.html', {
'form': form,
}
)
else:
try:
userprofile = UserProfile.objects.get(pk=request.user)
form = UserProfileForm({
'firstname': userprofile.firstname,
'lastname': userprofile.lastname,
'number': userprofile.number,
'serie': userprofile.serie,
'sexe': userprofile.sexe,
'phoneNumber': userprofile.phoneNumber,
})
except Exception as ex:
print ex
form = UserProfileForm()
return render(request,
'userprofile/userprofile_edit.html', {
'form': form,
}
)