python - How to get username in Django -


i need username show in

<li>     <a tabindex="-1" href="base_pages_profile.html">        <i class="si si-user pull-right"></i>             <span class="badge badge-success pull-right"></span>username     </a> </li> 

i have tried using request.user.username , request.get_username , not work, there other way this?

anything want access inside template need pass in context. in view have

 def someview(request):     template = loader.get_template('someview.html')     context = {         'username': request.user.username,     }     return httpresponse(template.render(context, request)) 

and in template can have

<span class="badge badge-success pull-right"></span>{{ username }}

alternatively can use context processors expose request or user or both templates default https://docs.djangoproject.com/en/dev/ref/templates/api/#context-processors


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -