Need to convert a string to int in a django template

前端 未结 6 1024
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-27 04:58


I am trying to pass in url parameters to a django template like this...

response = render_to_string(\'persistConTemplate.html\', request.GET)
         


        
6条回答
  •  Happy的楠姐
    2020-11-27 05:59

    The easiest way to do this is using inbuilt floatformat filter.

    For Integer

    {{ value|floatformat:"0" }}
    

    For float value with 2 precision

    {{ value|floatformat:"2" }}
    

    It will also round to nearest value. for more details, you can check https://docs.djangoproject.com/en/1.10/ref/templates/builtins/#floatformat.

提交回复
热议问题