Skip to content
Browse files

Made template names in django.contrib.auth.views passable as template…

…_name argument to the view

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent afe55af commit 6dfea737f627cb8c06b8feac0905136c3e55bae6 @adrianholovaty adrianholovaty committed Jun 6, 2006
Showing with 21 additions and 14 deletions.
  1. +12 −12 django/contrib/auth/
  2. +9 −2 docs/authentication.txt
24 django/contrib/auth/
@@ -9,7 +9,7 @@
from django.contrib.auth.decorators import login_required
from django.contrib.auth import LOGIN_URL, REDIRECT_FIELD_NAME
-def login(request):
+def login(request, template_name='registration/login.html'):
"Displays the login form and handles the login action."
manipulator = AuthenticationForm(request)
redirect_to = request.REQUEST.get(REDIRECT_FIELD_NAME, '')
@@ -25,18 +25,18 @@ def login(request):
errors = {}
- return render_to_response('registration/login.html', {
+ return render_to_response(template_name, {
'form': forms.FormWrapper(manipulator, request.POST, errors),
'site_name': Site.objects.get_current().name,
}, context_instance=RequestContext(request))
-def logout(request, next_page=None):
+def logout(request, next_page=None, template_name='registration/logged_out.html'):
"Logs out the user and displays 'You are logged out' message."
del request.session[SESSION_KEY]
except KeyError:
- return render_to_response('registration/logged_out.html', {'title': 'Logged out'}, context_instance=RequestContext(request))
+ return render_to_response(template_name, {'title': 'Logged out'}, context_instance=RequestContext(request))
# Redirect to this page until the session has been cleared.
return HttpResponseRedirect(next_page or request.path)
@@ -49,7 +49,7 @@ def redirect_to_login(next, login_url=LOGIN_URL):
"Redirects the user to the login page, passing the given 'next' page"
return HttpResponseRedirect('%s?%s=%s' % (login_url, REDIRECT_FIELD_NAME, next))
-def password_reset(request, is_admin_site=False):
+def password_reset(request, is_admin_site=False, template_name='registration/password_reset_form.html'):
new_data, errors = {}, {}
form = PasswordResetForm()
if request.POST:
@@ -61,13 +61,13 @@ def password_reset(request, is_admin_site=False):
return HttpResponseRedirect('%sdone/' % request.path)
- return render_to_response('registration/password_reset_form.html', {'form': forms.FormWrapper(form, new_data, errors)},
+ return render_to_response(template_name, {'form': forms.FormWrapper(form, new_data, errors)},
-def password_reset_done(request):
- return render_to_response('registration/password_reset_done.html', context_instance=RequestContext(request))
+def password_reset_done(request, template_name='registration/password_reset_done.html'):
+ return render_to_response(template_name, context_instance=RequestContext(request))
-def password_change(request):
+def password_change(request, template_name='registration/password_change_form.html'):
new_data, errors = {}, {}
form = PasswordChangeForm(request.user)
if request.POST:
@@ -76,9 +76,9 @@ def password_change(request):
if not errors:
return HttpResponseRedirect('%sdone/' % request.path)
- return render_to_response('registration/password_change_form.html', {'form': forms.FormWrapper(form, new_data, errors)},
+ return render_to_response(template_name, {'form': forms.FormWrapper(form, new_data, errors)},
password_change = login_required(password_change)
-def password_change_done(request):
- return render_to_response('registration/password_change_done.html', context_instance=RequestContext(request))
+def password_change_done(request, template_name='registration/password_change_done.html'):
+ return render_to_response(template_name, context_instance=RequestContext(request))
11 docs/authentication.txt
@@ -347,8 +347,8 @@ Here's what ``django.contrib.auth.views.login`` does::
It's your responsibility to provide the login form in a template called
-``registration/login.html``. This template gets passed three template context
+``registration/login.html`` by default. This template gets passed three
+template context variables:
* ``form``: A ``FormWrapper`` object representing the login form. See the
`forms documentation`_ for more on ``FormWrapper`` objects.
@@ -357,6 +357,13 @@ variables:
* ``site_name``: The name of the current ``Site``, according to the
``SITE_ID`` setting. See the `site framework docs`_.
+If you'd prefer not to call the template ``registration/login.html``, you can
+pass the ``template_name`` parameter via the extra arguments to the view in
+your URLconf. For example, this URLconf line would use ``myapp/login.html``
+ (r'^accounts/login/$', 'django.contrib.auth.views.login', {'template_name': 'myapp/login.html'}),
Here's a sample ``registration/login.html`` template you can use as a starting
point. It assumes you have a ``base.html`` template that defines a ``content``

0 comments on commit 6dfea73

Please sign in to comment.
Something went wrong with that request. Please try again.