86๐
โ
Thanks everyone for you help, it lead me to the realisation that I can use the with tag.
{% with list|last as last %}
{{ last.key }}
{% endwith %}
๐คJake
47๐
Use the last
template tag:
{{ value|last }}
If value is the list
['a', 'b', 'c', 'd']
, the output will be the string"d"
.
๐คmiku
- [Django]-Django REST Framework custom fields validation
- [Django]-User Registration with error: no such table: auth_user
- [Django]-Django: How to override form.save()?
9๐
In my case I find this solution: {{object_list.last.id}}
very useful on expression like this: {% url 'my-url' object_list.first.id object_list.last.id %}
๐คHelder
- [Django]-Itertools.groupby in a django template
- [Django]-Django and Restful APIs
- [Django]-Django ManyToMany model validation
6๐
You can mark the last forloop by the following tags
{% if forloop.last %} ... {% endif %}
and add you special desire inside the tags.
๐คDavid Louda
- [Django]-ImportError: Failed to import test module:
- [Django]-How can I get the object count for a model in Django's templates?
- [Django]-Cannot access django app through ip address while accessing it through localhost
- [Django]-Delete multiple objects in django
- [Django]-Django models: mutual references between two classes and impossibility to use forward declaration in python
- [Django]-Django datefield filter by weekday/weekend
0๐
It worked for my by simply counting the number of records inside the views.py file using the built in function count() and then check if the forloop.counter != total_count then add and
{% if forloop.counter != total_jobs %}
<hr>
{% endif %}
๐คSafiullah Khan
- [Django]-Check if key exists in a Python dict in Jinja2 templates
- [Django]-Dynamic choices field in Django Models
- [Django]-Include intermediary (through model) in responses in Django Rest Framework
- [Django]-How do I go straight to template, in Django's urls.py?
- [Django]-Check if key exists in a Python dict in Jinja2 templates
- [Django]-CSRF validation does not work on Django using HTTPS
Source:stackexchange.com