我有一个通过ajax更新用户数据的函数
def ajax_update(request):
if request.method == 'POST':
update_form = forms.UserUpdateForm(request.POST, instance=request.user)
if update_form.is_valid():
update_form.save()
response['status'] = 'success'
return JsonResponse(response)
和一个UserUpdateForm
class UserUpdateForm(forms.ModelForm):
class Meta:
model = User
exclude = ['password']
def save(self, commit=True):
instance = super(UserUpdateForm, self).save(commit=False)
instance.set_password(self.cleaned_data['password_1'])
instance.save()
return instance
执行set_password并保存实例后,返回“success”消息。
但是,当我重新加载页面时,它的会话已过期