tickets: 22752
This data as json
id | created | changetime | last_pulled_from_trac | stage | status | component | type | severity | version | resolution | summary | description | owner | reporter | keywords | easy | has_patch | needs_better_patch | needs_tests | needs_docs | ui_ux |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
22752 | 2014-06-02 20:00:36 | 2021-01-19 02:27:01 | 2022-03-06 04:20:10.458304 | Accepted | assigned | contrib.auth | Cleanup/optimization | Normal | dev | Allow PasswordResetForm email to render URLs based on the current namespace | I have multiple namespace instances for password reset urls. The email template rendered by the default PasswordResetForm does not included a `current_app` context. It's an easy fix, though, ass the PasswordResetForm already has `self.current_app`. Just need to wrap the context instance passed to the email template: {{{ #!diff diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py index 6e07d45..baef873 100644 --- a/django/contrib/auth/forms.py +++ b/django/contrib/auth/forms.py @@ -4,7 +4,7 @@ from collections import OrderedDict from django import forms from django.forms.utils import flatatt -from django.template import loader +from django.template import loader, Context from django.utils.encoding import force_bytes from django.utils.html import format_html, format_html_join from django.utils.http import urlsafe_base64_encode @@ -264,10 +264,13 @@ class PasswordResetForm(forms.Form): 'token': token_generator.make_token(user), 'protocol': 'https' if use_https else 'http', } - subject = loader.render_to_string(subject_template_name, c) + context_instance = Context(current_app=self.current_app) + subject = loader.render_to_string( + subject_template_name, c, context_instance) # Email subject *must not* contain newlines subject = ''.join(subject.splitlines()) - email = loader.render_to_string(email_template_name, c) + email = loader.render_to_string( + email_template_name, c, context_instance) if html_email_template_name: html_email = loader.render_to_string(html_email_template_name, c) ~ }}} | hramezani | bendavis78 | 0 | 0 | 0 | 0 | 0 | 0 |