我使用python在django表单中工作。 Iam在保存editform时遇到问题。
如果iam使用字段和文本字段更改保存表单,则其工作正常(使用更新的内容刷新)。 但是,如果我通过更改图像字段和字段来保存表单,则更新但不刷新页面。
我希望在更新或保存详细信息后刷新页面。 在此先感谢。
MY VIEWS.PY:
def profile_page(request,type = None):
profile_list = get_object_or_404(UserProfile, visit_id = request.user.username, profile_type = type)
image = UserProfile.objects.get(visit_id = request.user.username, profile_type = type).image
if request.method == "POST":
form = UserProfileForm(request.POST, request.FILES)
if form.is_valid():
new_image = form.cleaned_data['image']
if new_image == None:
current_image=form.fields['image'].initial = profile_list.image
else:
person = UserenaSignup.objects.get(visitid = request.user.username).id
UserImage.objects.filter(username = person, profile_type = type).delete()
current_image = UserImage.objects.create(username_id = person, profile_type = type, image = form.cleaned_data['image']).image
UserProfile.objects.filter(visit_id = request.user.username, profile_type = type).update(username = form.cleaned_data['username'],
designation = form.cleaned_data['designation'],
image = current_image,
)
return render_to_response('profile_page.html',locals(),context_instance = RequestContext(request))
else:
form = UserProfileForm(instance = profile_list)
return render_to_response('profile_page.html', locals(), context_instance=RequestContext(request))
else:
form = UserProfileForm(instance = profile_list)
return render_to_response('profile_page.html',locals(),context_instance = RequestContext(request))
答案 0 :(得分:0)
您可以尝试从此行的末尾删除.image
:
current_image = UserImage.objects.create(username_id = person, profile_type = type, image = form.cleaned_data['image']).image