I use some third-party template tags in my Django Application (maintained elsewhere) that return a username as a string I can access in my templates like this.
{% for user in gr.user.foll.list %}
{{user}}
Trouble is because {{user}} is returned as a string - I need to convert into a Django User Object, if it exists in the Django DB, or set a varible unRegistered if not so I can do things like:
{ user.get_profile.about }} # get profile information
So I thought I would write my first Django Template Tag so I could use it like this:
{% webapp_user_lookup user %} # my custom tag
{% ifnot unRegistered %}
{{ user.get_profile.about }} # get profile information - would fail with a string
{% endifnot %}
{% endfor %}
The code I use elsewhere to look up a user in a view is:
try:
user = User.objects.get(username__iexact=user)
unRegistered = False
if not other_user.is_active:
unRegistered = True
except:
unRegistered = True
However looking at the Django Template tag examples I'm having trouble understanding how best to structure the custom template tag, to take my string username - and send back the results as an object if they exist, or set a varible if not and the original string. I'd really like to better understand how the structure works, and if I need a 'class' and if so, why. (I'm new to programming).