active = request.POST['isactive']
if active == 'True':
user_profile.user.is_active = False
elif active == 'False':
user_profile.user.is_active = True
user_profile.user.save()
嗨,我正在尝试通过切换按钮更新用户状态;用户状态在数据库中更新,但没有反映在用户界面上。还尝试了事务提交,但没有运气。请帮助解决此问题的解决方案 谢谢!
修改: 添加表单代码
{% if isactive == True %}
<button type="submit" form="form1" class="block">Block</button>
{% elif isactive == False %}
<button type="submit" form="form1" class="unblock">Unblock</button>
{% endif %}
<form method="POST" id="form1" action="" >
{% csrf_token %}
<input type="hidden" id="isactive" name="isactive" value="{{ isactive }}">
</form>