How do I customize the input format accepted by Django auth's PasswordResetView?

I'm using Django 3.1 witih Python 3.9. I'm using Django's django.contrib.auth application to manage my users. I would like to setup a reset password for my users, using Django's "PasswordResetView", but am unsure how to customize it to suit submitting a JSON request. I have created this in my urls.py file

path('reset_password/', views.ResetPasswordView.as_view(), name='password_reset'),
path('password-reset-confirm/<uidb64>/<token>/',
     auth_views.PasswordResetConfirmView.as_view(template_name='users/password_reset_confirm.html'),
     name='password_reset_confirm'),
path('password-reset-complete/',
     auth_views.PasswordResetCompleteView.as_view(template_name='users/password_reset_complete.html'),
     name='password_reset_complete'),

Defined this in my views.py file

class ResetPasswordView(SuccessMessageMixin, PasswordResetView):
    template_name = 'users/password_reset.html'
    email_template_name = 'users/password_reset_email.html'
    subject_template_name = 'users/password_reset_subject'
    success_message = "We've emailed you instructions for setting your password, " \
                      "if an account exists with the email you entered. You should receive them shortly." \
                      " If you don't receive an email, " \
                      "please make sure you've entered the address you registered with, and check your spam folder."
    success_url = reverse_lazy('users-home')

and defined these in my settings.py file

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtppro.zohopro.com'
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER = str(os.getenv('EMAIL_USER'))
EMAIL_HOST_PASSWORD = str(os.getenv('EMAIL_PASSWORD'))

However, when I submit a POST request to my endpoint with the data

{"username": "myuser@example.com"}

in which "myemail@example.com" is a registered user, I get back

curl: (52) Empty reply from server

The specific curl request looks like the below, for what it's worth ...

curl -v 'http://localhost:8000/reset_password' \
  -H 'sec-ch-ua: "Not?A_Brand";v="8", "Chromium";v="108", "Google Chrome";v="108"' \
  -H 'sec-ch-ua-platform: "macOS"' \
  -H 'Referer: http://localhost:3000/' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36' \
  -H 'Content-Type: application/json' \
  --data-raw '{"username":"myuser@example.com"}' \
  --compressed

How do I customize what input the PasswordResetView will accept?

Back to Top