Yes
For example, in the filter {{
var|foo:"bar"
}}, the filter foo would be passed the variable var and the argument "bar".
I want to pass 2 (maybe 3) variables and correct me if I am wrong but
Custom filters are just Python functions that take one or two arguments:
So could do {{ var|foo:”bar, bar2” }}
or {{ var|foo:”bar” “bar2” }} and pass 2 arguments? The doc doesn’t specify
I assume if 2 args
def cut(value, arg1, arg2):
?
--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/zG3S_9BQKMY/unsubscribe.
To unsubscribe from this group and all its topics, 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/553d2ac6-cac1-4b9a-b3bd-2a4f5934ae47%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I am so rusty I’m having trouble writing a simple_tag
In the template
{% for b in list %}
{% load get_cost %}{% do_cost {{ b.name }} avn avd %}
Also tried (per docs) {% do_cost name={{ b.name }} avn=avn avd=avd %}
I definitely have values in the template passed from the view for avn and avd and of course b.name
Tag
from django import template
from django.conf import settings
from django.utils.html import escape
from band.models import Data
register = template.Library()
@register.simple_tag
def do_cost( name, avn, avd, *args, **kwargs ):
avn = kwargs['avn']
avd = kwargs['avd']
name = kwargs['name']
val = Data.objects.filter(property=name).filter(date_period=date)
return val
I just keep getting do_cost takes 3 arguments
*** I know I want it to take 3 arguments!!!!***
Is it telling me that I can’t use {{ b.name }} as an arg?
--
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/de8c0f7e-c8ee-4329-a954-457acfd01c64%40googlegroups.com.
Thank you Andreas Kuhne, progress
Exception Type: | TemplateSyntaxError |
---|---|
Exception Value: | Caught KeyError while rendering: 'avn' |
--
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/8d9d18dd-c8cb-494c-a2b8-8b06b64c40d3%40googlegroups.com.
Ah I was just doing that to prove it was working
This is the actual tag
from django import template
from django.conf import settings
from django.utils.html import escape
from band.models import Data
register = template.Library()
@register.simple_tag
def do_cost( name, avn, avd, *args, **kwargs ):
avn = kwargs['avn']
avd = kwargs['avd']
name = kwargs['name']
val_set = Data.objects.filter(prop = name).filter(date_period=avd)
avn = 7 #this line is just for testing
if avn >= 7:
for x in val_set:
val = x.full
else:
for x in val_set:
val = x.short
return val
From: django...@googlegroups.com [mailto:django...@googlegroups.com] On Behalf Of Andréas Kühne
Sent: 22 August 2018 15:20
To: django...@googlegroups.com
Subject: Re: template tag help please?
Wait a secound, you are doing some very strange things....
--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/zG3S_9BQKMY/unsubscribe.
To unsubscribe from this group and all its topics, 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/CAK4qSCcnJzyrWXGjTyF9NZAc0SE6zxQ1gbrd1ZM2Oc%2B3ZL_tyQ%40mail.gmail.com.
avn = kwargs['avn']
avd = kwargs['avd']
name = kwargs['name']
That is unnecessary....
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5b7d7953.1c69fb81.85c08.097dSMTPIN_ADDED_BROKEN%40gmr-mx.google.com.
Andreas,
Thank you for your help and patience I have got the damned thing working!!
It helped that I remembered that one of the filter arguments was actually a foreign key in the model and had to be an integer id not a string, that was being obfuscated by being a templatetag call.
Thank you
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAK4qSCcbeyp%2B33YCNmK6w053X14-4Noqxm2KWPj58A-rs8EJrA%40mail.gmail.com.
--
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/8d7b9f60-9f88-41c6-8fec-cf858d7e6574%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHLKn714iMAzyE%3DaXn_tyJQos-xLWPrWS6BEfFq013%3DS-rmShA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAO87g13Nmssbp_VPv6ktJmpRrSOasusm%2BvPnDhKGZe_o9yBZ%2BQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHLKn70NnEcJLNH5-8nnc%2B90TaTx3iqCiXuiVAdd6xop_teX7g%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAO87g10CtF%3Dj7C5ZbGYSKX1J7DFRNPDgfbLBAwNVXhWYPmdS0w%40mail.gmail.com.