title: Django password reset _getfullpathname error
body: <p>I am trying to set up a password reset form but I get the following error after trying to send an email, weirdly I noticed that if I put email that doesn't match any of the emails provided by users it works, error only occurs when email matches one provided by a user.
  Error:</p>
  <pre><code>TypeError at /password_reset/
  _getfullpathname: path should be string, bytes or os.PathLike, not NoneType
  </code></pre>
  <p>urls.py</p>
  <pre><code>from django.contrib.auth import views as auth_views #import this
  
  urlpatterns = [
      ...
      path('accounts/', include('django.contrib.auth.urls')),
      path('password_reset_done/', auth_views.PasswordResetDoneView.as_view(template_name='registration/password_reset_done.html'), name='password_reset_done'),
      path('reset/&lt;uidb64&gt;/&lt;token&gt;/', auth_views.PasswordResetConfirmView.as_view(template_name=&quot;registration/password_reset_confirm.html&quot;), name='password_reset_confirm'),
      path('reset/done/', auth_views.PasswordResetCompleteView.as_view(template_name='registration/password_reset_complete.html'), name='password_reset_complete'),
      path(&quot;password_reset/&quot;, views.password_reset_request, name=&quot;password_reset&quot;),
  ]
  </code></pre>
  <p>views.py</p>
  <pre><code>def password_reset_request(request):
      if request.method == &quot;POST&quot;:
          password_reset_form = PasswordResetForm(request.POST)
          if password_reset_form.is_valid():
              data = password_reset_form.cleaned_data['email']
              associated_users = User.objects.filter(Q(email=data))
              if associated_users.exists():
                  for user in associated_users:
                      subject = &quot;Password Reset Requested&quot;
                      email_template_name = &quot;registration/password_reset_email.txt&quot;
                      c = {
                      &quot;email&quot;:user.email,
                      'domain':'127.0.0.1:8000',
                      'site_name': 'Website',
                      &quot;uid&quot;: urlsafe_base64_encode(force_bytes(user.pk)),
                      &quot;user&quot;: user,
                      'token': default_token_generator.make_token(user),
                      'protocol': 'http',
                      }
                      email = render_to_string(email_template_name, c)
                      try:
                          send_mail(subject, email, 'admin@example.com' , [user.email], fail_silently=False)
                      except BadHeaderError:
                          return HttpResponse('Invalid header found.')
                      return redirect (&quot;/password_reset/done/&quot;)
      password_reset_form = PasswordResetForm()
      return render(request=request, template_name=&quot;registration/password_reset_form.html&quot;, context={&quot;password_reset_form&quot;:password_reset_form})
  </code></pre>
  <p>password_reset_form.html</p>
  <pre><code>{% extends 'base.html' %}
  
  {% block content %}
  
              
  
      &lt;!--Reset Password--&gt;
      &lt;div class=&quot;container p-5&quot;&gt;
          &lt;h2 class=&quot;font-weight-bold mt-3&quot;&gt;Reset Password&lt;/h2&gt;
          &lt;hr&gt;
          &lt;p&gt;Forgotten your password? Enter your email address below, and we'll email instructions for setting a new one.&lt;/p&gt;
          &lt;form method=&quot;POST&quot;&gt;
              {% csrf_token %}
              {{ password_reset_form }}                    
              &lt;button class=&quot;btn btn-primary&quot; type=&quot;submit&quot;&gt;Send email&lt;/button&gt;
          &lt;/form&gt;
      &lt;/div&gt; 
  
  {% endblock %}
  </code></pre>
  <p>I have added <code>'django.contrib.auth'</code> to my INSTALLED_APPS and <code>EMAIL_BACKEND = &quot;django.core.mail.backends.filebased.EmailBackend&quot;</code> line in  settings.py</p>