简体   繁体   中英

How to send password reset email from django using django-rest-framework and React

I'm creating a website in the backend i'm using (django,django-rest-framework) and frontend (React.js). I'm not clearly understand how do i create restfull api for password reset email.

The library Django Rest Auth (different from django rest framework's auth app) helps with this. https://github.com/Tivix/django-rest-auth

Backend

Install rest_auth into INSTALLED_APPS on the backend, and set up a URL

urlpatterns = [
  ...
  path('rest-auth/', include('rest_auth.urls')),
]

Frontend Once that's in place, you can send a post request to the password reset endpoint, and it'll send out an email using Django's built-in mail handling (I use django-anymail to get it to send through mailgun, but any email backend will work)

This is a snippet from react-native, but you can use an equivalent web library like axios or jQuery to make the post request.

  async resetPassword() {
    const { email } = this.state;
    fetch("https://mywebsite.com/api/v1/rest-auth/password/reset/", {
      method: "POST",
      body: JSON.stringify({email}),
    })
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM