[Django]-Django template convert to string

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👍

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  %}

Leave a comment