The Python Oracle

AttributeError: 'bool' object has no attribute

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Forest of Spells Looping

--

Chapters
00:00 Question
01:10 Accepted answer (Score 3)
01:59 Answer 2 (Score 0)
02:46 Thank you

--

Full question
https://stackoverflow.com/questions/5036...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #django #djangoforms #djangoviews

#avk47



ACCEPTED ANSWER

Score 3


'bool' object has no attribute 'has_created_artist_profile' means you're trying to access the attribute has_created_artist_profile of a boolean object (True or False), rather than that of an object.

For example: True.has_created_artist_profile will produce the exact same error.

From your code, you set artist_status to that of a boolean which was part of an object (current_artist), and then tried to access a property from that boolean.

As advised, you have removed the artist_status variable, and you are now using the current_artist object directly.




ANSWER 2

Score 0


The Python "AttributeError: 'bool' object has no attribute" occurs when we try to access an attribute on a boolean value (True or False). To solve the error, track down where you are setting the value to a boolean or use the hasattr() method to check for the attribute's existence.

Here is how the error occurs.

 artist_status.has_created_artist_profile = True

You are trying to access an attribute on a boolean (True or False) instead of on the object. If you print() the value you are accessing the attribute on, it will be a boolean. So you need to track down where exactly you are setting the value to a boolean in your code and correct the assignment.