[Django]-UnboundLocalError- local variable referenced before assignment – Django

8👍

This is happening because request.method == 'POST' is True (first condition passes) but form.is_valid() is False (second nested condition fails), which means the final return after the else is run but ctxt is not defined.

Perhaps you intended that final return to be indented as a part of the else clause?

Leave a comment