i get an unicode error when trying url like www.mysite.com/blog/category/πρακτικα/ or www.mysite.com/blog/πρακτικα/
but i dont get the error when trying www.mysite.com/blog/tag/πρακτικα/
UnicodeEncodeError at /blog/category/πρακτικα/ 'latin-1' codec can't encode characters in >position 58-65: ordinal not in range(256)
Exception Location: /home/vagrant/sullogos-venv/local/lib/python2.7/site-packages/django/template/loaders/filesystem.py in load_template_source, line 37
seems it haves different behavior at categories and at tags
The difference is that categories can have a custom template and tags can't. So in the category case, a template name is searched for using the category slug - the error you're getting is due to an incorrectly configured locale which doesn't support utf8.
This is not a problem with Mezzanine or Django, but with the environment used to deploy them. See this issue and this documentation for more details. It's not enough for Python to support a specific locale, but it's also necessary for the webserver to be able to handle Unicode files correctly.
How to fix it will depend on the webserver used. If you're using Apache, for instance, you need to set LANG and LC_ALL to Unicode-compatible values (on *NIX systems at least you should find them at /etc/apache2/envvars). An example would be:
export LANG='en_US.UTF-8'
export LC_ALL='en_US.UTF-8'
Feel free to replace the language/country codes with another one more suitable for your needs (I used pt_BR instead of en_US and things worked fine for me). From the error message you're seeing, these settings in your system are probably using ISO-Latin (ISO-8859-1) instead of UTF-8 (which I assume can't handle cyrillic).
If you're using a different webserver, check its documentation on localization/internationalization to see what needs to be changed. The important thing is to offer support to Unicode file names, as I understood.
Related
I want to use font awersome in my project in the way, that user can choose which icon he wants. I found django-fontawesome-5 but there is one problem - there is no access to icon's unicode and I need it for one javascript component (html doesn't work there, and unicode does). I was looking all over the internet, but I coundn't find anything that would allow me to add font-awersome icons, with their unicodes somhow stored. My question is do you know how to get this feature?
The unicode codes are stored in icons.json and in icons_semantic_ui.json
Since you've got the codes source you can define a custom templatetag or a model/mixin method or a function which just gets a code from one of those json files using icon name
You can see example in fontawesome_5/utils.py
I create a django application with existing MySQL database, the problem is the encoding to database is latin1_general_c and the utf8 characters is save like this ñ => ñ , ó => ó, i need present the information in that page in correctly form but django show the information of database like this
recepción, 4 oficinas, 2 baños
i need show like this
recepcíon, 4 oficinas, 2 baños
For many reasons I can't change the database to utf8
what do I do for show information the correctly way?
Django seems to explicitly require that your database use UTF-8:
Django assumes that all databases use UTF-8 encoding. Using other encodings may result in unexpected behavior.
That said, it should be possible to use the custom OPTIONS setting to pass the desired character set to the database driver. See this answer, in which setting charset solved the problem. But you should check the documentation for the specific MySQL driver and database that you're using, since these options are not used by Django itself.
As suggested by the quote above, even if this works to correctly translate strings between the database and unicode, parts of Django still won't work correctly. For example, to correctly validate the length of a CharField Django has to know the encoding, and it will always assume UTF-8.
I'm trying to run a django website on my local computer. It works fine on an external server, but I didn't set it up and right now I don't have access to all the specs.
The issue I have is when I try to log in the web site as a user, which has been defined. Running in debug mode I get a detailed error page containing on top the message:
UnicodeDecodeError at /accounts/login/
'ascii' codec can't decode byte 0xe2 in position 0: ordinal not in range(128)
Looking down I can see that the error occurs in crypto.py, function salted_hmac at the line
key = hashlib.sha1((key_salt + secret).encode('utf-8')).digest()
and displaying the local variables I see
key_salt u'django.contrib.sessionsSessionStore'
secret '\xe2\x80\x9cXXX"'
value '{}'
where XXX is a 50 character string identical to the SECRET_KEY defined in my configuration file. Variable secret is assigned in the function through:
if secret is None:
secret = settings.SECRET_KEY
and I know that secret is None at this point since it is a third parameter in salted_hmac not used by the caller. I strongly suspect that the error occurs because python can not handle the unicode characters at the beginning of the variable secret.
So I have a few questions:
1) Why is setting.SECRET_KEY different from the SECRET_KEY I defined in the configuration file? Is it how it should be? And if it is do I have any control over what it should be?
2) Could something in my environment be responsible for this?
A few notes: As I mentioned it works on a server, running ubuntu 1.6, python 2.7. However I can not right now obtain the info on the versions for the other packages. But even if I could I still want to know why it doesn't work on my installation. I have tested with django 1.6.1, python 2.7 on lubuntu 14.04, opensuse 13.2, with identical results.
Thanks for any help or hint.
a
Problem solved: the secret key in my configuration file started with an (unicode) opening quote, instead of a regular double quote, probably a result of copying and pasting the original file that had been written with an editor that uses these "smarter" quotes.
Django's default LANGUAGES settings contains zh-cn and zh-tw. However, I would like to use zh instead of zh-tw. I've set up my LANGUAGES setting appropriately and compiled the gettext messages but Django will only load the zh-cn translation.
Frustratingly, gettext will load the zh translation fine if I delete the zh_CN directory!
Is there any way to get zh to load the right translation?
My assumption on this is because django itself is only translated into zh-cn and zh-tw. Django translation will only allow you to translate into a language Django itself is translated for.
You should try to translate Django into zh (or copy zh-tw into zh).
Maybe the "Using Gettextize software" from GNU C help.
http://www.gnu.org/software/libc/manual/html_node/Using-gettextized-software.html
Quote:
The file /usr/share/locale/locale.alias (replace /usr with whatever
prefix you used for configuring the C library) contains a mapping of
alternative names to more regular names. The system manager is free to
add new entries to fill her/his own needs. The selected locale from
the environment is compared with the entries in the first column of
this file ignoring the case. If they match the value of the second
column is used instead for the further handling.
Note that the in some system (e.g. Fedora 21), /usr/system/locale/locale.alias is obsoleted and just for backward compatibility.
I have problem when i trying add pictures with not only ascii characters through admin interface.
It always seems to trying convert name of picture's file to ascii:
UnicodeEncodeError at /admin/app/subpicture/add/
('ascii', u'/home/celtrun/rails/alphasteel/public/media/my_media/subpictures/Zdj\u0119cia_iPhone_wrzesie\u0144_320.jpg', 68, 69, 'ordinal not in range(128)')
Request Method: POST
Django Version: 1.3
Exception Type: UnicodeEncodeError
Exception Value:
('ascii', u'/home/celtrun/rails/alphasteel/public/media/my_media/subpictures/Zdj\u0119cia_iPhone_wrzesie\u0144_320.jpg', 68, 69, 'ordinal not in range(128)')
Exception Location: /bin/python-2.6.1/lib/python2.6/genericpath.py in exists, line 18
Python Executable: /bin/python-2.6.1/bin/python
And:
Unicode error hint
The string that could not be encoded/decoded was: s/Zdjęcia_i
Result is that the picture that i try to save don't appear in specified repository. The picture's files are saved in this repository if its names don't have unicode characters in file's name.
Has someone have any ideas to fix this?
After 2 years I'm having same problem with CentOS6.4 and Django 1.5.
While I search a solution I think that even I upload a file with special characters I may encounter problems with other applications. So I tried this. Using ASCII for files is better than using unicode names. Not every program support ığüşöçâİ or font. It may also cause font problems in websites.
The default Apache environment on Ubuntu/*nix doesn't allow non-ASCII file names. This leads to
the rather unintuitive UnicodeEncodeError when submitting unicode filenames in a filefield/imagefield
in Django admin.
Try adding this to the Apache config (/etc/apache2/envvars):
export LANG='en_US.UTF-8'
export LC_ALL='en_US.UTF-8'
And then restart the apache server.