0


I would like to add the username of the user on pages like change_password.
I don't think I can pass the username as extra context for in the url like that:

url(r'^password_change/$','django.contrib.auth.views.password_reset', ),'extra_context':{'user_name': 'alexis'})

because I need to change 'alexis' to resquest.user.get_username() and I don't have access to the resquest.
I also tried to create a custom view but it doesn't work:

from django.contrib.auth.views import password_change_done
def my_password_change(request):

return password_change_done(request,'password/password_change_form.html','extra_context':{'user_name': 'alexis'})

Thank you in advance for any input.
Alexis.

Alexis Benoist
  • 2,400
  • 2
  • 17
  • 23

1 Answers1

0

The username of the currently logged-in user should already be available in the template via {{ user.username }} (if using the context processor django.contrib.auth.context_processors.auth - which is highly recommended).

Bernhard Vallant
  • 49,468
  • 20
  • 120
  • 148
  • 1
    Not quite right. The auth processor is enabled by default (unlike the request one) but it makes `user` available directly, not via `request`. – Daniel Roseman May 26 '13 at 16:36
  • Im wondering about something, I use '{{ user.username }}' in my templates and the display of the name is not consistant, sometime it's appears and sometimes it doesn't. Any idea why? – Alexis Benoist May 26 '13 at 18:02
  • @AlexisBenoist You should just be careful if maybe one of your views specifies an object in the context that is also called _user_. Otherwise it should always be the logged-in user, except if you're not logged in, then it is an instance of `AnonymousUser`. – Bernhard Vallant May 26 '13 at 18:24