我正在使用将LANGUAGE_CODE
设置为es
的Django APP。
我正在尝试格式化数字在模板中的呈现方式。现在,当需要S/ 18,00
时,它们的呈现方式如下:S/ 18.00
。
我搜索并找到了另一个相关问题:
Format numbers in django templates
但是在应用Humanize之后,我没有得到想要的结果:
template.html:
{% load humanize %}
<p>El total de su pedido es: S/ {{ total|intcomma }}</p> #renders S/ 18,00
settings.py:
# 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)<p>El total de su pedido es: S/ {{ total|floatformat:'2' }}</p>
不起作用,在需要S/ 18,00
时呈现:S/ 18.00
。
2)<p>El total de su pedido es: S/ {{ total|stringformat:"f" }}</p>
有效,但使用两个以上的小数:需要S/ 18.00000000
时使用S/ 18.00
。
3)<p>El total de su pedido es: S/ {{ total|stringformat:"2f" }}</p>
这不起作用,并且在需要S/ 18.00000000
时也返回:S/ 18.00
。
models.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)
views.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的评论为我指明了正确的方向。
R'relaimpo'软件包的Python端口 - python我需要计算Lindeman-Merenda-Gold(LMG)分数,以进行回归分析。我发现R语言的relaimpo包下有该文件。不幸的是,我对R没有任何经验。我检查了互联网,但找不到。这个程序包有python端口吗?如果不存在,是否可以通过python使用该包? python参考方案 最近,我遇到了pingouin库。
如何用'-'解析字符串到节点js本地脚本? - python我正在使用本地节点js脚本来处理字符串。我陷入了将'-'字符串解析为本地节点js脚本的问题。render.js:#! /usr/bin/env -S node -r esm let argv = require('yargs') .usage('$0 [string]') .argv; console.log(argv…
Python:传递记录器是个好主意吗? - python我的Web服务器的API日志如下:started started succeeded failed 那是同时收到的两个请求。很难说哪一个成功或失败。为了彼此分离请求,我为每个请求创建了一个随机数,并将其用作记录器的名称logger = logging.getLogger(random_number) 日志变成[111] started [222] start…
Python-Excel导出 - python我有以下代码:import pandas as pd import requests from bs4 import BeautifulSoup res = requests.get("https://www.bankier.pl/gielda/notowania/akcje") soup = BeautifulSoup(res.cont…
django-compressor未与django-shop一起安装 - python我无法使用django-shop安装django-compressor。出现这样的错误。Failed building wheel for rcssmin ================================= Failed building wheel for rjsmin -----------------------------------…