Python 人性化不使用模板中的浮动
我正在开发一个Django应用程序,它将西班牙语的Python 人性化不使用模板中的浮动,python,django,Python,Django,我正在开发一个Django应用程序,它将西班牙语的LANGUAGE\u code设置为es 我正在尝试格式化如何在模板中呈现数字。现在它们呈现为:S/18,00当需要S/18.00时 我搜索并发现了另一个相关问题: 但在应用“人性化”后,我没有得到理想的结果: template.html: {% load humanize %} <p>El total de su pedido es: S/ {{ total|intcomma }}</p> #renders S/ 1
LANGUAGE\u code
设置为es
我正在尝试格式化如何在模板中呈现数字。现在它们呈现为:S/18,00
当需要S/18.00
时
我搜索并发现了另一个相关问题:
但在应用“人性化”后,我没有得到理想的结果:
template.html:
{% load humanize %}
<p>El total de su pedido es: S/ {{ total|intcomma }}</p> #renders S/ 18,00
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'shop',
'django.contrib.humanize',
]
我还尝试了以下其他解决方案:
1) El total de su pedido es:S/{{total | floatformat:'2'}
不工作,当需要S/18.00
时渲染:S/18,00
2) El total de su pedido es:S/{{total | stringformat:“f”}
工作,但使用超过2位小数:S/18.00000000
当需要S/18.00
时
3) El total de su pedido es:S/{{total | stringformat:“2f”}
这不起作用,当需要S/18.00
时,还会返回:S/18.00000000
型号。py:
class Order(models.Model):
token = models.CharField(max_length=100, blank=True, null=True)
first_name = models.CharField(max_length=50, blank=True, null=True)
last_name = models.CharField(max_length=50, blank=True, null=True)
total = models.DecimalField(max_digits=10, decimal_places=2)
视图.py
def thanks_deposit_payment(request):
order_number = Order.objects.latest('id').id
total = Order.objects.latest('id').total
response = render(request, 'thanks_deposit_payment.html', dict(order_number=order_number, total=total))
return response
其他可能有帮助的语言设置:
LANGUAGE_CODE = 'es'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
我只需在我的
settings.py
文件中关闭这两个变量:
USE_I18N = False #Before True
USE_L10N = False #Before True
在模板中,我可以使用:
{{ total }}
感谢Kendoka的评论为我指明了正确的方向。我只需在我的
settings.py
文件中关闭这两个变量:
USE_I18N = False #Before True
USE_L10N = False #Before True
在模板中,我可以使用:
{{ total }}
感谢肯多卡的评论为我指出了正确的方向。你是否尝试过
{total | floatformat:2 | intcomma}
?另外,给我一个机会:{%loadl10n%}{%localizeon%}{total}{%endlocalize%}
我现在已经测试过了,得到了相同的结果:s/18,00
或者:{%loadl10n%}{{value | localize}
或者您是否尝试过{total | floatformat:2 | intcomma}
?另外,试一试:{%load l10n%}{%localize on%}{total}{%endlocalize%}
我现在已经测试过了,得到了相同的结果:S/18,00
或者:{%load l10n%{value}{localize code}