Home > database >  How can I use tag set in Django(jinja)?
How can I use tag set in Django(jinja)?

Time:04-17

I want use below code in Django template but I get this error : Invalid block tag on line 255: 'set'. Did you forget to register or load this tag?.

{% set  Ne_page = page_data.current_page  1 %}
{% set  Pr_page = page_data.current_page -1 %}

When I use {% load set %} for load set tag I get this error: 'set' is not a registered tag library. Must be one of: admin_list, admin_modify, admin_urls,...

I use another function like if or for and ... and work fine but when use set I have error, How can I use set tag for increment a variable?

CodePudding user response:

Yes you can use {% set %} to create variable to store data in Jinja but django uses it's own template engine not Jinja but if you want to use Jinja then you can change default Template Engine to create variable in django use {% with %} for addition use add

{% with  Ne_page=page_data.current_page|add:" 1" %}
{% endwith %}

{% with  Pr_page=page_data.current_page|add:"-1" %}
{% endwith %}

Note : you've to use your variable in between with endwith block
eg.

{% with alpha=1 %}
   {{alpha}} use it inside block
{% endwith %}
  • Related