How can I get information about the logged-in user in a Django application?
For example:
I need to know the username of the logged-in user to say who posted
if you are using the old way of writting views, in the way of Function-Based-Views...
in your view, you are creating a new variable called usuario to save the request.user probably...
but if you returning to the Template a context_instance, passing the value of the Context of the request, you will get the logged user, just by accessing the request.
// In your views file
from django.shortcuts import render_to_response
from django.template import RequestContext
def your_view(request):
data = {
'formulario': Formulario()
# ...
}
return render_to_response('your_template.html',
data, context_instance=RequestContext(request))
// In your template