1

Ok Here goes.

With django-registration i have created a user with passwords etc. I have named the user Zoro. The registration was a success and it takes me to

"You are now registered. Activation email sent."

Email activation is turned off. So i go to login page and login. This is done under 127.0.0.1/accounts/login. The login.html template successfully extends the base.html template. And within the base.html template i have a tag {{ user }}, which i want to show the username at the top left.

When i login my urls are extended away from ^/accounts/login to ^/homepage. Know i dont know where the current username is stored, so i cant pass to {{ user }} the curent user's name in views. So {{ user }} is blank.

But.......If i go back to the login page, the current username is at the top left.

I am new, be gentle.

jsanchezs
  • 1,992
  • 3
  • 25
  • 51
ragingbull
  • 119
  • 1
  • 2
  • 8

1 Answers1

2

You have different options to add the {{ user }} to your templates context:

a) add django.contrib.auth.context_processors.auth to your TEMPLATE_CONTEXT_PROCESSORS setting. This will make a {{ user }} template variable available in all context's when rendering templates.

b) do it by hand and add a user variable to pass it to the context in your view. user can be retrieved from request.user

c) Make sure you are not overwrting {{ user }} somewhere.

Torsten Engelbrecht
  • 13,318
  • 4
  • 46
  • 48