url_safe_base64_encode returns string, and strings don't have decode method. However, bytes objects have decode method.
string.encode will change string to bytes. bytes.decode will change bytes to string. On Thu, Jul 18, 2019 at 8:28 PM Ahmet İnal <[email protected]> wrote: > > > What's wrong taht code if i try register i seeing. > > AttributeError at /register/ > > 'str' object has no attribute 'decode' > > 'uid':urlsafe_base64_encode(force_bytes(user.pk)).decode('utf-8'), whats > problem on this line. > > class MyUserCreationForm(UserCreationForm): > class Meta: > # Yeni Model > model = User > # Yeni alanlar > fields = { 'username', 'password1', 'password2', 'email',} > exclude = ['Avatar','gender','birth_date',] > > > > > > def clean_username(self): > username = self.cleaned_data['username'].lower() > if username in blacklist: > raise ValidationError("Lütfen başka bir kullanıcı adı seçin.") > return username > > def save(self, commit=True): > user = super(UserCreationForm, self).save(commit=True) > current_site = Site.objects.get_current() > mail_subject = 'Activate your blog account.' > message = render_to_string('includes/emails/activation-mail.html', { > 'user': user, > 'domain': current_site.domain, > 'uid':urlsafe_base64_encode(force_bytes(user.pk)).decode('utf-8'), > 'token':account_activation_token.make_token(user), > }) > to_email = form.cleaned_data.get('email') > email = EmailMessage( > mail_subject, message, to=[to_email] > ) > email.send() > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/0b4256b7-080a-4f85-b4e3-e741ec8447ac%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/0b4256b7-080a-4f85-b4e3-e741ec8447ac%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- Regards, Aldian Fazrihady http://aldianfazrihady.com -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAN7EoAa3Uz%2B3911ZDYoBvbk9MX7BmGDKhoESC9%3Dp0up5DYG1XQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.

