I am trying to get the data from django's user model and print the full name of a user from it.
view.py
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
def Showfullname (request):
fullname = request.user.get_full_name()
context = {'fullname':fullname}
return render(request, 'main/base.html', context)
the line for it from urls.py
url(r'^name$', views.Showfullname, name='Showfullname'),
and then the div that is the target in my main files, where I already have a is authenticated check in a parent template.
<div class="form-group has-feedback">
<input type="text" class="form-control" placeholder="{% url 'main:Showfullname' %}" readonly />
<i class="glyphicons glyphicons-car form-control-feedback"></i>
</div>
Right now it prints
/ in the input when it should be printing dan dan or admin admin
You can use {{full_name}}
in your Django template. Also, if your user is authenticated you can use {{request.user.get_full_name}}
in the template.
In the template, you can use this to get the full name
<h3>{{request.user.get_full_name}}</h3>
it returns the first_name plus the last_name, with a space in between. docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With