meeb/django-distill

 character being generated by distill-local

Closed this issue · 3 comments

Hello, I am using django-distill to build a site locally and when I generate the site, every time I use the builtin humanize "naturaltime" filter an "Â" character is inserted in between the number and the time (e.g. "19Â hours ago"). This is not occurring on either my development server, or the production apache server I am using - only during the local generation of django-distill.

Any ideas where I might be able to go to fix this? Do I need to specify utf8 encoding somewhere for django-distill to use?
Thanks so much for the help!

meeb commented

What's your settings.LANGUAGE_CODE set to? Also is LocaleMiddleware loaded?

meeb commented

There isn't actually anything wrong here, everything is working correctly (really). The humanize template tags do not return spaces between some values, they return Unicode non-breaking spaces. These aren't ASCII spaces \x20 they are the Unicode character \xc2\xa0. More info is available here:

https://en.wikipedia.org/wiki/Non-breaking_space

This means that the output of django_distill is the same as you are getting in your local development server and production server. The reason you are seeing  appear is likely because you are not setting the Content-Type header correctly on static HTML files, which should be something like:

Content-Type: text/html; charset=utf-8

(your web server is probably missing the charset=utf-8 part off). This is being set for you by Django when the site is being executed by Python which is why the page works correctly when not being statically rendered.

You probably need to add something like this to your Apache config:

AddDefaultCharset utf-8

or possibly this:

AddCharset utf-8 .html

In summary, this is likely a configuration issue with your Apache web server and the way you are serving statically written HTML files and not to do with DJango or django_distill.

I've added some tests to confirm this behaviour as well.