Reputation: 5228
payment-tags.py
@register.simple_tag
def has_purchased(user_id):
payments = Payment.objects.all(user__id=user_id)
return PaymentObjects(payments)
class PaymentObjects(template.Node):
def __init__(self, payments):
print 'inside init'
self.payments_obj = payments
def render(self, context):
print 'inside render'
context['payments'] = self.payments_obj
return ''
Indside html:
{% load payment-tags %}
{% has_purchased request.user.id %}
The render method of PaymentObjects class never get called, It goes inside the init function but not inside render..
I had searched this issue on google but didn't got any satisfactory answer which can solve the issue.
Any advice would be greatly appreciated, Thanks.
Upvotes: 1
Views: 756
Reputation: 129764
register.simple_tag
is used for tag functions that immediately return the result (Django creates the node for you). If you want to return your own node, use register.tag
instead.
Upvotes: 2