Reputation: 5
I designed a website using django mezzanine platform and it goes completely alright. I just have a problem with utf-8 numbers which I used in pages (actually persian numbers). you see, in django templates it shows numbers as english digits, and when I wanted to show numbers in persian(utf-8) i had to use a custom template tag, which transform all numericals into persian. (I provided the code). but in mezzanine templates it also had to use another custom template tag which implements html tags in WYSIWYG editor. my problem is when I want to combine these 2 template tags it breaks. especially when the page has image in it. consider the "richtext_filters" use the width and height provided by string, and the numbers before getting to them has changed to utf-8 digits, and then the error I entered as the title appears:
'ascii' codec can't encode character '\u06f1' in position 83: ordinal not in range(128)
or the other error:
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'.
I also considered changing "locale" on my shared host provider, but didn't have any clue either. appreciate any help.
any code needed is here: my custom template tag:
# -*- 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))
and also the template:
{{ page.richtextpage.content|persianize_digits|richtext_filters }}
if you want to know the "richtext_filters", here it's the code: (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)
Upvotes: 0
Views: 67