Instead of directly accessing the value through ["category"], use get instead so whenever a missing value is presented this will return None. task.category = request.POST.get('category')
["category"]
task.category = request.POST.get('category')
please refer to this