Wednesday, July 29, 2015

Want to change template based on full_name(request.user.username)

Hello All,

I am facing an issue in my first django project. I am newbie. So, please help me in detail. I don't want to use {{full_name}} in all the views. I saw few post which says {{user.is_authenticated}} can be used. I tried but it was not working. Passing {'full_name':request.user.username} to each is very hectic. Also, not sure to this in one of my view where i am using password_change. View is mentioned below where i am not able pass full_name.

This is mentioned below is my navigation.html


<nav class="navbar navbar-default">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <!--<a class="navbar-brand" href="/" >Arham Collections</a>-->
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li class="active"><a href="/">Home <span class="sr-only">(current)</span></a></li>
        <li><a href="#">Sale <span class="sr-only">(current)</span></a></li>
        <li><a href="#">About Us</a></li>
      
      </ul>
<!--      <form class="navbar-form navbar-left" role="search">
        <div class="form-group">
          <input type="text" class="form-control" placeholder="Search">
        </div>
        <button type="submit" class="btn btn-default">Submit</button>
      </form>-->
      <ul class="nav navbar-nav navbar-right">

        {%if full_name %}
        
        <li class="dropdown">
            
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">{{full_name}}<span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="/useraccount/edit_user">My Account</a></li>
            <li><a href="#">Orders</a></li>
            <li><a href="/useraccount/edit_user">Profile</a></li>
            <li><a href="/useraccount/change-password">Change Password</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="/useraccount/logout">Logout</a></li>
          </ul>
        </li>
        {% else %}
        <li><a href="/useraccount/register">Register</a></li>
        <li><a href="/useraccount/login">Login</a></li>
        {% endif %}
      </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>

--------------------------------------------------------------------------------------------------------------------------------------------------------
@login_required
def my_change_password_view(request,template_name='useraccount/password_change_form.html'):
    return password_change(request,template_name)
----------------------------------------------------------------------------------------------------------------------------------------------------------

Please help.

Regards,
Sarfaraz Ahmed

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f8521d79-c2a0-40a9-bd4e-0a90625264fe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment