我正在使用 python 以 django 形式工作。保存编辑表单时遇到问题。
如果我使用 charfield 和 textfield 更改保存表单,则它的工作正常(使用更新的内容刷新)。但是,如果我通过更改图像字段和字符字段来保存表单,它会更新但不刷新页面。
我希望在更新或保存详细信息后刷新页面。提前致谢。
我的观点.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))