python - 尝试访问路径中包含 unicode 字符的文件,但不知何故,当前语言环境不支持 utf-8
问题描述
我使用django 夹层平台设计了一个网站,它完全没问题。我只是对utf-8 数字有疑问我在页面中使用的(实际上是波斯数字)。你看,在 django 模板中它将数字显示为英文数字,当我想以波斯语(utf-8)显示数字时,我必须使用自定义模板标签,它将所有数字转换为波斯语。(我提供了代码)。但在夹层模板中,它还必须使用另一个自定义模板标签,该标签在 WYSIWYG 编辑器中实现 html 标签。我的问题是当我想组合这两个模板标签时它会中断。特别是当页面中有图像时。考虑“richtext_filters”使用字符串提供的宽度和高度,并且在到达它们之前的数字已更改为utf-8位,然后出现我作为标题输入的错误:
'ascii' codec can't encode character '\u06f1' in position 83: ordinal not in range(128)
或其他错误:
Access was attempted on a file that contains unicode characters in its path, but somehow the current locale does not support utf-8. You may need to set 'LC_ALL' to a correct value, eg: 'en_US.UTF-8'.
我还考虑在我的共享主机提供商上更改“语言环境”,但也没有任何线索。感谢任何帮助。
需要的任何代码都在这里:我的自定义模板标签:
# -*- coding: utf-8 -*-
from django import template
from datetime import datetime
@register.filter(name='persianize_digits')
def persian_int(string):
persianize = dict(zip("0123456789",'۰۱۲۳۴۵۶۷۸۹'))
return ''.join(persianize[digit] if digit in persianize else digit for digit in str(string))
还有模板:
{{ page.richtextpage.content|persianize_digits|richtext_filters }}
如果你想知道“richtext_filters”,这里是代码:(mezzanine.utils.html)
width = img.get("width")
height = img.get("height")
if src_in_media and str(width).isdigit() and str(height).isdigit():
img["src"] = settings.MEDIA_URL + thumbnail(src, width, height)
解决方案
推荐阅读
- visual-studio-code - 在 VS Code 中一次击键执行多个命令
- sql - MSSQL - 如何将 cpu_time(ms) 使用率转换为百分比?
- angular - 实现 ngRx 时出错“类型‘操作’上不存在属性‘管道’
’。” - python-3.x - pyhf中小信号模型的拟合收敛失败
- python - 多通道卷积神经网络 - 负维度尺寸误差
- javascript - 将气泡中的行添加到数据图上的弹出模板
- kubernetes - 有没有办法根据我的集群当前资源来限制 cpu 的使用?
- google-chrome - 无法连接到 Twilio:信号连接错误
- sql-server - 子查询返回超过 1 个值。当子查询跟随 =、!=、<、<=、>、>= 时,这是不允许的
- jquery - jQuery DateTimePicker 插件 - 相应地更改标题文本