R
R
Romua1d2016-11-02 00:10:38
Django
Romua1d, 2016-11-02 00:10:38

How to output template tag with if?

@register.inclusion_tag('html_tags/callbacktags/count_callbaks.html')
def count_callbacks():
    data = CallBacks.objects.filter(read=False).count()
    return {'data': data }

we have a template tag
how to display this tag on the site?
{% if count_callbacks != 0 %}
Count = {% count_callbacks %}
{% endif %}

Thank you!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Romua1d, 2016-11-02
@Romua1d

Answer: ( Here )
Register the tag as assignment_tag

@register.assigment_tag
def count_callbacks():
    data = CallBacks.objects.filter(read=False).count()
    return {'data': data }

Accordingly, the output will be like this:
{% count_callbacks as cc%}
{% if cc.data != 0 %}
Count = {{ cc.data }}
{% endif %}

S
Sergey Gornostaev, 2016-11-02
@sergey-gornostaev

{% count_callbacks as cc %}
{% if cc.data != 0 %}
Count = {{ cc.data }}
{% endif %}

And count_callbacks by all accounts doesn't apply to inclusion tags, use the simple_tag decorator .

K
Konstantin Kitmanov, 2017-01-11
KuzmenkoArtem

> The error is clear. If I go with the administrator, then it can be bypassed.
It's not clear to me. By default, programs launched by the user have the right to write to his ~. And from the root, all the more such problems should not be.
> The question is, what is the /home/user/.npm folder for?
There will be a cache and global (delivered with -g) modules will be placed there.
> Simply if it is necessary, then I need other users to have access to it
Hmm, why?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question