You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using Django Rest Framework alongside Django 4.2.6.
I am using the from django.utils.translation import activate function just before the send_password and send_email functions but the messages are failing to be translated in my responses. The response always defaults to the default language of the server that is stated in the settings.py file. How can I overcome this problem?
The text was updated successfully, but these errors were encountered:
I had to make the emails Thread=False to make it work. I would add a language section to the method so that users can pass languages:
def send_auth_email(user, type: str = "verification", language: str = "en") -> None:
"""
The function sends an authentication email to a user, either for verification or password reset, in
the specified language.
Args:
user: The "user" parameter represents the user object or user information that will be used to
send the authentication email.
type (str): The "type" parameter is used to specify the type of email to be sent. It can have two
possible values: "verification" or "reset". Defaults to verification
language (str): The "language" parameter is a string that specifies the language in which the
email should be sent.
"""
translation.activate(language)
if type == "verification":
send_email(user, thread=False)
elif type == "password_reset":
send_password(user, thread=False)
translation.deactivate()
I am using
Django Rest Framework
alongsideDjango 4.2.6
.I am using the
from django.utils.translation import activate
function just before thesend_password
andsend_email
functions but the messages are failing to be translated in my responses. The response always defaults to the default language of the server that is stated in thesettings.py
file. How can I overcome this problem?The text was updated successfully, but these errors were encountered: