94
You can use stringformat
to convert a variable to a string:
{{ value|stringformat:"i" }}
See documentation for formatting options (the leading %
should not be included).
17
You can use {{ value|slugify }}
(https://docs.djangoproject.com/en/1.10/ref/templates/builtins/).
- [Django]-ImportError: cannot import name 'url' from 'django.conf.urls' after upgrading to Django 4.0
- [Django]-Celery – Get task id for current task
- [Django]-How do I use Django templates without the rest of Django?
3
just create a new template tag
from django import template
register = template.Library()
@register.filter
def to_str(value):
"""converts int to string"""
return str(value)
and then go to your template and add in the top of the file
{% load to_str %}
{ number_variable|to_str %}
- [Django]-How to run a celery worker with Django app scalable by AWS Elastic Beanstalk?
- [Django]-Find Monday's date with Python
- [Django]-How to get the value of a Django Model Field object
Source:stackexchange.com