Looking at your form_valid
function:
The ModelForm.save
method returns the object being saved.
Therefore, changing that line to new_user = form.save()
gives you the new user that you just created.
That means you don’t need the user_email
line, because you have access to that field as user_email = new_user.email
That means your context for your render_to_string
call can look like this:
{
'user': new_user,
'domain': current_site.domain,
'uid': urlsafe_base64_encode(force_bytes(new_user.pk)),
'token': account_activation_token.make_token(new_user),
}