Skip to content Skip to sidebar Skip to footer

Why Am I Getting This Error? Attributeerror: 'str' Object Has No Attribute 'decode'

I am trying to create a registration page with email verification. I am new in Python Dajngo webdevelopment. Currently I using Python 3.6, Django 2.2.4, Postgresql 11 and Ubuntu OS

Solution 1:

You should learn to read your error traces, usually they tell you exactly what's going on.

In this case the error location (Exception Location) was the line

'uid': urlsafe_base64_encode(force_bytes(user.pk)).decode()

and the error was str type does not have attribute decode, meaning that

urlsafe_base64_encode(force_bytes(user.pk))

is apparently str, not a byte-string and therefore you cannot apply the method decode to it. The next step is to check the documentation for urlsafe_base64_encode where you'll read that in Django 2.2, this returns a str.

Great! So with Django 2.2, no need to decode what used to be bytestring, just pass the string that you got from urlsafe_base64_encode directly to your mail template.

Post a Comment for "Why Am I Getting This Error? Attributeerror: 'str' Object Has No Attribute 'decode'"