从 django 用户模型获取用户全名

Han*_*ish 8 python django

我正在尝试从 django 的用户模型获取数据并从中打印用户的全名。

视图.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)
Run Code Online (Sandbox Code Playgroud)

来自urls.py的行

url(r'^name$', views.Showfullname, name='Showfullname'),
Run Code Online (Sandbox Code Playgroud)

然后是我的主文件中的目标 div,其中我已经在父模板中进行了身份验证检查。

<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>
Run Code Online (Sandbox Code Playgroud)

现在它打印

/ 在输入时应该打印 dan dan 或 admin admin