title: User Account activation email using Django
body: <p>I am trying to create User Registration form . User account will be activated by activation email.
  Following error is coming:-</p>
  
  <p>Exception Type: NoReverseMatch at /register/ Exception Value: Reverse for 'activate' not found. 'activate' is not a valid view function or pattern name.</p>
  
  <p>I followed following links :</p>
  
  <p><a href="https://studygyaan.com/django/how-to-signup-user-and-send-confirmation-email-in-django" rel="nofollow noreferrer">https://studygyaan.com/django/how-to-signup-user-and-send-confirmation-email-in-django</a></p>
  
  <p><a href="https://blog.hlab.tech/part-ii-how-to-sign-up-user-and-send-confirmation-email-in-django-2-1-and-python-3-6/" rel="nofollow noreferrer">https://blog.hlab.tech/part-ii-how-to-sign-up-user-and-send-confirmation-email-in-django-2-1-and-python-3-6/</a></p>
  
  <p><a href="https://medium.com/@frfahim/django-registration-with-confirmation-email-bb5da011e4ef" rel="nofollow noreferrer">https://medium.com/@frfahim/django-registration-with-confirmation-email-bb5da011e4ef</a></p>
  
  <pre class="lang-py prettyprint-override"><code>def register(request):
      if request.method == 'POST':
          form = NewUserForm(request.POST)
          if form.is_valid():
              user = form.save(commit=False)
              user.is_active = False
              user.save()
              current_site = get_current_site(request)
              mail_subject = 'Activate your blog account.'
              message = render_to_string('website/acc_active_email.html', {
                  'user': user,
                  'domain': current_site.domain,
                  'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                  'token': account_activation_token.make_token(user=user),
              })
              to_email = form.cleaned_data.get('email')
              email = EmailMessage(
                  mail_subject, message, to=[to_email]
              )
              email.send()
              return HttpResponse('Please confirm your email address to complete the registration')
          else:
              for msg in form.error_messages:
                  print(form.error_messages[msg])
      else:
          print('in else')
          form = NewUserForm()
      return render(request=request, template_name='website/register.html', context={'form': form})
  
  def activate_account(request, uidb64, token):
      try:
          uid = force_bytes(urlsafe_base64_decode(uidb64))
          user = User.objects.get(pk=uid)
      except(TypeError, ValueError, OverflowError, User.DoesNotExist):
          user = None
      if user is not None and account_activation_token.check_token(user, token):
          user.is_active = True
          user.save()
          login(request, user)
          return HttpResponse('Your account has been activate successfully')
      else:
          return HttpResponse('Activation link is invalid!')
  
  </code></pre>
  
  <p>My html file code</p>
  
  <pre class="lang-html prettyprint-override"><code>{% autoescape off %}
  Hi {{ user.username }},
  Please click on the link to confirm your registration,
  http://{{ domain }}{% url 'activate' uidb64=uid token=token %}
  {% endautoescape %}
  </code></pre>