[Solved] local variable ‘content_type’ referenced before assignment
You only set content_type when your form is valid: if comment_form.is_valid(): # … content_type = ContentType.objects.get_for_id(content_type_id) # … else: print(comment_form.errors) So when comment_form.is_valid() is false, the variable is never set. You have the same issue with object_id_data and content_data. Perhaps you need to re-think what should be returned when the form is not correct? It … Read more