如果您的
IntegrityError
是 None 类型,似乎会出现问题 enteredValue
。确保您发送的值有效。
此外,像这样修改你的
edit
视图来处理这种情况
enteredValue = request.POST.get('edited_task')
get_task = get_object_or_404(Task, pk=pk)
if enteredValue is not None:
get_task.task = enteredValue
get_task.save()
return redirect('home')
这样,您只会在提供非 NULL 值时更新任务,这将避免
not NULL CONSTRAINT
错误。