Discussion:
custom filter tag I can't get to work
(too old to reply)
Rookies DJ
2018-12-06 07:49:14 UTC
Permalink
I create my own custom filter tags to using in my project but every time i
put in my HTML it just product this errors Invalid filter:

I don't where i do wrong, I try putting the {%load tag%} with child
templates, it didn't work

I try name it differently

@register.filter("multiply", multiply) @register.filter(name="multiply")
@register.filter()

didn't work either

Here my HTML code that include the filter:

<div class = "float-right my-4 chartjs-render-monitor" id="chartContainerPH" style="width: 49%; height: 400px;display: inline-block; background-color:#FDFDFD;">
<center>
<a class="title-link" href="{%url 'ph' %}">PH:</a>
<p> {{tank_system.PH|latest}}, </p>

</center>
</div>


and here my code for my custom filter


from django import template
register = template.Library()

@register.filter('latest', latest)
def custom_last(value):
last = None

try:
last = value[-1]
except AssertionError:
try:
last = value.reverse()[0]
except IndexError:
pass

return last


my views


from django.shortcuts import render
from django.views.generic import TemplateView
from zigview.models import tank_system

from django.contrib.auth.decorators import login_required
import logging
logger = logging.getLogger(__name__)


try:
@login_required(login_url='/accounts/login/')
def index(request): #gose to main dashboard page
tank = tank_system.objects.all
return render(request, 'FrounterWeb/extends/includes.html', {'tank': tank})
except:
logger.error('index page request failed/errors')


I intend to use two custom filter
--
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 post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/97860011-3621-4c46-b654-67a9c95d33af%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...