dj-rest-auth Reset email link keeps pointing to the backend


I’m using dj-rest-auth with react and i’m trying to use the frontend url instead of the backend url. The solution i am using for the account creation confirmation email affects the reset password email too but only partially. It does not effect the port. It only tries to add a key to the reset link where there is none and throws me an error.

So i was wondering if there is a way to change the url from port 8000 to port 3000.
This is what i have tried:

class AccountAdapter(DefaultAccountAdapter):
    def is_open_for_signup(self, request: HttpRequest):
        return getattr(settings, "ACCOUNT_ALLOW_REGISTRATION", True)

    def send_mail(self, template_prefix, email, context):
        if settings.DEBUG:
            context["activate_url"] = (
                "http://localhost:3000/accounts/confirm-email/" + context["key"]
            context["activate_url"] = (
                settings.FRONTEND_URL + "/accounts/confirm-email/" + context["key"]
        return super().send_mail(template_prefix, email, context)

If i get rid of the key part it doesn’t give me an error but keeps port 8000 and breaks my account confirmation emails. If i don’t get rid of the key it gives me:

django          |     "http://localhost:3000/accounts/confirm-email/" + context["key"]
django          | KeyError: 'key'


This fixed it for me:

class CustomAllAuthPasswordResetForm(AllAuthPasswordResetForm):
    def save(self, request, **kwargs):
        current_site = get_current_site(request)
        email = self.cleaned_data['email']
        token_generator = kwargs.get('token_generator',

        for user in self.users:

            temp_key = token_generator.make_token(user)

            # save it to the password reset model
            # password_reset = PasswordReset(user=user, temp_key=temp_key)

            # send the password reset email
            path = reverse(
                args=[user_pk_to_url_str(user), temp_key],
            url = build_absolute_uri(None, path) # PASS NONE INSTEAD OF REQUEST

            context = {
                'current_site': current_site,
                'user': user,
                'password_reset_url': url,
                'request': request,
            if app_settings.AUTHENTICATION_METHOD != app_settings.AuthenticationMethod.EMAIL:
                context['username'] = user_username(user)
                                           email, context)
        return self.cleaned_data['email']

class CustomPasswordResetSerializer(PasswordResetSerializer):
    def password_reset_form_class(self):
        return CustomAllAuthPasswordResetForm


Answered By – Matthias

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published