request and email templates

2 views
Skip to first unread message

Tim Miller

unread,
Dec 13, 2009, 12:06:15 PM12/13/09
to django...@googlegroups.com
I'm using django.contrib.auth.views.password_reset and trying to pass
the ip address of the user requesting a password reset into the
confirmation email.

I've enabled django.core.context_processors.request in settings and can
successfully display request.META.REMOTE_ADDR in the form.html template
but can't seem to access request at all within the email template.

From what I've been reading and trying, I don't believe I can directly
pass a context to this generic view so I'm wondering if there's
something simple I'm missing or if I need to abandon the shortcuts and
just write my own custom view.

urls.py snipped:

urlpatterns = patterns('django.contrib.auth',

(r'^reset/$', 'views.password_reset', {
'template_name': 'users/reset/form.html',
'email_template_name': 'users/reset/email.html',
'post_reset_redirect': 'done/',
}),

)


Tim.

Daniel Roseman

unread,
Dec 13, 2009, 2:28:17 PM12/13/09
to Django users
Looking at the code for that view, in
django.contrib.auth.views.password_reset, it appears that the actual
email creation and sending happens in the save method of the
PasswordResetForm, and the request is not passed into that method at
all so is not available in the template.

To make this work, you'd have to override both the view and the form.

It's not an unreasonable thing to want to do though - if you're keen,
raise a ticket with a patch.
--
DR.

Tim Miller

unread,
Dec 14, 2009, 12:43:14 AM12/14/09
to Django users
Daniel Roseman wrote:
> Looking at the code for that view, in
> django.contrib.auth.views.password_reset, it appears that the actual
> email creation and sending happens in the save method of the
> PasswordResetForm, and the request is not passed into that method at
> all so is not available in the template.
>
> To make this work, you'd have to override both the view and the form.
>
> It's not an unreasonable thing to want to do though - if you're keen,
> raise a ticket with a patch.
> --
> DR.

Thanks for the help. Opened a ticket with a rudimentary patch.

http://code.djangoproject.com/ticket/12372
Reply all
Reply to author
Forward
0 new messages