[Answered ]-Django Templates: How best can the output of executing python code in a Django template be suppressed?

1👍

Also you can use with tag and ignore variable:

{% with ignorevar=Counter.increment %}{% endwith %}
👤frist

1👍

This is a bit of a hack, but it would solve your problem:

{{ Counter.increment|yesno:"," }}

(See the documentation on the yesno filter)

0👍

If you only need the top five elements, then I think the right way is to send a list of only top 5 elements from your views to your your html templates in the very first place.

Also, if for some reason, you are not able to do that, then you should there is a thing in Django known as Template Tags where you do all your calculations.

See this -> https://docs.djangoproject.com/en/1.9/howto/custom-template-tags/

And finally if you still want to use Counter.increment, then simply put it inside a div say “count-flag” and using your javascript, hide that div forever on page load:

$(document).on('ready', function(){
    $("#count-flag").hide();
}

So it will not be displayed on your html, but technically this is not the way to do it.

Leave a comment