[Answer]-UnboundLocalError: local 'category' variable referenced before assignment

1👍

That traceback does not match your code. The view code says Category.DoesNotExist while the traceback shows category.DoesNotExist. The former works because the class Category is defined. The latter will not work because category doesn’t yet exist when the exception is raised by Category.objects.get().

If the view code above is accurate then you’re having some other problem that’s causing stale code to be executed.

Leave a comment