The Python Oracle

AttributeError: 'bool' object has no attribute

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 5 Looping

--

Chapters
00:00 Attributeerror: 'Bool' Object Has No Attribute
01:01 Accepted Answer Score 3
01:41 Answer 2 Score 0
02:17 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.