Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14185

register=template.library() TypeError: 'module' object is not callable

$
0
0

I have writen a custom filter to show the number of products that has been added to cart page.here's custom filter cart_tags.py

from django import templatefrom order.models import Orderregister=template.library()@register.filter(name="cart_total")def cart_total(user):    order=Order.objects.filter(user=user,ordered=False)     if order.exists():        return order[0].orderitems.count()    else:        return 0

navbar.html to show the use the filter

{% load cart_tags %}<li class="nav-item"><a href="{% url 'cart' %}" class="nav-link"><i class="fa fa-shopping-cart"></i> Cart<span class="badge badge-light">{{ request.user | cart_total}}</span></a></li>

I have also created init.py in templatetags folder.But it shows me this error in terminal

 File "C:\Users\ITS\Desktop\my-e-com-project\E_commerce\order\templatetags\cart_tags.py", line 4, in <module>    register=template.library()TypeError: 'module' object is not callable

Help me with this please


Viewing all articles
Browse latest Browse all 14185

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>