本文整理汇总了Python中forms.ProfileForm.as_table方法的典型用法代码示例。如果您正苦于以下问题:Python ProfileForm.as_table方法的具体用法?Python ProfileForm.as_table怎么用?Python ProfileForm.as_table使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.ProfileForm
的用法示例。
在下文中一共展示了ProfileForm.as_table方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: form_profile_ajax
# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import as_table [as 别名]
def form_profile_ajax(request):
if request.method == 'POST':
form = ProfileForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
try:
user_profile = request.user.get_profile()
except UserProfile.DoesNotExist:
##create profile
user_profile = UserProfile(user=request.user)
##update profile
user_profile.country = cd['country']
user_profile.about = cd['about']
user_profile.save()
##update User
User.objects.filter(username=request.user.username).update(first_name = cd['first_name'],
last_name = cd['last_name'],
email = cd['email'] )
#a cool thing to return the html generated by rendering a template in Json:
#html = render_to_string(template, {'review': review })
##can also use: if request.is_ajax() to be sure that javascript is allowed
return HttpResponse(json.dumps({'form_ok':True,
'form_uncomplete':any(map(lambda x: x=='', cd.values())),
'html':ProfileForm(cd).as_table()}),
mimetype='application/json')
else: #form not valid, we resubmit it with error msg so that the user correct it
return HttpResponse(json.dumps({'form_ok':False,
'form_uncomplete':False,
'html':form.as_table()}),
mimetype='application/json')
else: ##user is not authentified
return HttpResponseRedirect('/profile')