0

I want to learn how use the Django authentication system.I can create group and add permission to it and create users and add them to group.

I want when user log-in, on top of the page, I can show the name of user who is loggin-in and put logout link near it like most of the real website. how can I do this? should I use user profile? if yes where and how should I use it?

Hasan Ramezani
  • 5,004
  • 24
  • 30
user3789719
  • 104
  • 1
  • 10

1 Answers1

0

Create a header.html template like this:

<div class="header"> 
    <ul> 
        <li> Username: {{ user.username}} </li> 
        <li><a href='/logout'> Logout</a> </li>
    </ul>
</div>

You can include this template in every template that you want to show username and logout link like this:

{% include "header.html" %}

And in your views.py you can pass user object to template like this:

def test(request):
user = request.user
variables = RequestContext( request,
    {
        'user': user,
    }
)
return render_to_response( 'test.html', variables )
Hasan Ramezani
  • 5,004
  • 24
  • 30
  • Thanks.it helps me.I have one question that I create user profile in model but I don't know how use it?could you say how use it or give some useful source? – user3789719 Oct 26 '14 at 21:59
  • see [django doc](https://docs.djangoproject.com/en/1.4/topics/auth/#storing-additional-information-about-users), and [this](http://stackoverflow.com/questions/6085025/django-user-profile) – Hasan Ramezani Oct 26 '14 at 22:03