Custom template tags - instance.templatetag

19 views
Skip to first unread message

Jan Gregorczyk

unread,
Jun 2, 2020, 4:53:06 PM6/2/20
to Django users
Hi! How to change my template tag?
from django import template

register = template.Library()

@register.simple_tag
def votes_up_exists(answer, user_id):
pass

how I use it - {% votes_up_exists answer request.user.id %}
how I would like to use it - {% answer.votes_up_exists user_id %}

Andréas Kühne

unread,
Jun 3, 2020, 5:42:39 AM6/3/20
to django...@googlegroups.com
Hi Jan,

You can't do it like that. A templatetag is a simple function that is handled in a special way by the django templating language.

See here for an explanation:


Med vänliga hälsningar,

Andréas


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c0aba2c4-b13d-4ba2-9478-d32661c81307%40googlegroups.com.

Andréas Kühne

unread,
Jun 3, 2020, 5:43:25 AM6/3/20
to django...@googlegroups.com
Sorry - I posted that without a link?


This is by design - and you should always try to simplify what you are doing in django templates.

Regards,

Andréas

The Sha

unread,
Jun 9, 2020, 8:36:38 AM6/9/20
to Django users
Reply all
Reply to author
Forward
0 new messages