-
#agregar templatetags a APPS de settings
-
-
1.-
-
apps/templatetags/userInfoTag.py
-
-
# -*- coding: utf-8 -*-
-
from django import template
-
from django.shortcuts import get_object_or_404
-
from django.contrib.auth.models import User
-
-
register = template.Library()
-
@register.inclusion_tag(‘admin/users/inclusionTags/userRecordsTags.html’, takes_context=True)
-
def userRecords(context):
-
request = context[‘request’]
-
user = get_object_or_404(User, id=request.user.id)
-
userName = user.first_name + ‘ ‘ + user.last_name
-
-
return {‘userName’: userName}
-
-
2.-
-
apps/templatetags/__init__.py
-
from django.template import add_to_builtins
-
add_to_builtins(‘templatetags.userInfoTag’)
-
-
3.-
-
templates/admin/users/inclusionTags/userRecordsTags.html
-
{{ userName }} # return value of userInfotag.py
-
-
4.-
-
-
#se puede usar la plantilla userRecords.html en culaquiera otra plantilla
-
-
templates/admin/users/indexSuccess.html
-
<td>{% userRecords %}</td> #def userRecords