From 6dfea737f627cb8c06b8feac0905136c3e55bae6 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Tue, 6 Jun 2006 05:16:05 +0000 Subject: [PATCH] Made template names in django.contrib.auth.views passable as template_name argument to the view git-svn-id: http://code.djangoproject.com/svn/django/trunk@3087 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/auth/views.py | 24 ++++++++++++------------ docs/authentication.txt | 11 +++++++++-- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/django/contrib/auth/views.py b/django/contrib/auth/views.py index f919f82419..f917bab952 100644 --- a/django/contrib/auth/views.py +++ b/django/contrib/auth/views.py @@ -9,7 +9,7 @@ from django.http import HttpResponse, HttpResponseRedirect 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): else: errors = {} request.session.set_test_cookie() - return render_to_response('registration/login.html', { + return render_to_response(template_name, { 'form': forms.FormWrapper(manipulator, request.POST, errors), REDIRECT_FIELD_NAME: redirect_to, '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." try: 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)) else: # 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): else: form.save() 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)}, context_instance=RequestContext(request)) -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: form.save(new_data) 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)}, context_instance=RequestContext(request)) 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)) diff --git a/docs/authentication.txt b/docs/authentication.txt index 804f0326c1..79a4ed0875 100644 --- a/docs/authentication.txt +++ b/docs/authentication.txt @@ -347,8 +347,8 @@ Here's what ``django.contrib.auth.views.login`` does:: form. It's your responsibility to provide the login form in a template called -``registration/login.html``. This template gets passed three template context -variables: +``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`` +instead:: + + (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`` block::