{"action":"created","issue":{"url":"https://api.github.com/repos/pallets/jinja/issues/392","repository_url":"https://api.github.com/repos/pallets/jinja","labels_url":"https://api.github.com/repos/pallets/jinja/issues/392/labels{/name}","comments_url":"https://api.github.com/repos/pallets/jinja/issues/392/comments","events_url":"https://api.github.com/repos/pallets/jinja/issues/392/events","html_url":"https://github.com/pallets/jinja/issues/392","id":52277883,"number":392,"title":"Support Unicode literals in templates","user":{"login":"eastside","id":3721132,"avatar_url":"https://avatars.githubusercontent.com/u/3721132?v=3","gravatar_id":"","url":"https://api.github.com/users/eastside","html_url":"https://github.com/eastside","followers_url":"https://api.github.com/users/eastside/followers","following_url":"https://api.github.com/users/eastside/following{/other_user}","gists_url":"https://api.github.com/users/eastside/gists{/gist_id}","starred_url":"https://api.github.com/users/eastside/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eastside/subscriptions","organizations_url":"https://api.github.com/users/eastside/orgs","repos_url":"https://api.github.com/users/eastside/repos","events_url":"https://api.github.com/users/eastside/events{/privacy}","received_events_url":"https://api.github.com/users/eastside/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2014-12-17T19:03:52Z","updated_at":"2016-04-15T19:42:59Z","closed_at":null,"body":"Sometimes, it makes sense to format a character in a string literal--\r\n\r\n```\r\n{{ \"{0} is fantastic\".format(user.full_name) }}\r\n```\r\n\r\nHowever, this will fail with a UnicodeEncodeError if user.full_name is a Unicode string with non-ASCII characters in it.\r\n\r\nJinja2 does not support unicode string literals, so one must work around this problem like so--\r\n\r\n```\r\n{{ \"{0} is fantastic\".decode(\"utf8\").format(user.full_name) }}\r\n```\r\n\r\nThis is icky. Could Jinja2 be changed in the future to support the Unicode literal? Our example code would look like this--\r\n\r\n```\r\n{{ u\"{0} is fantastic\".format(user.full_name) }}\r\n```\r\n\r\nThis mirrors what you would likely do in a Python script, which I think is what Jinja2 is going for.\r\n\r\nAside: I think you might be wondering what the real use case is for this. Obviously, in the example I've used it would be easy to just write this:\r\n\r\n```\r\n{{ user.full_name }} is fantastic!\r\n```\r\n\r\nOne example of where a unicode literal makes sense is encoding a querystring. For example, imagine we have a mailto link with some default body and subject text, which we want to format. This pattern makes sense:\r\n\r\n```\r\n{% set mailto_dict = {\r\n    \"body\": \"{0} is fantastic!\".decode(\"utf8\").format(user.full_name),\r\n    \"subject\": \"And this is some example text! Sincerely, {0}\".decode(\"utf8\").format(business.full_name),\r\n} %}\r\n<a href=\"mailto:?{{ mailto_dict|urlencode }}\">Send an email</a>\r\n```\r\n\r\nBut all those `decode(\"utf8\")` are icky. It would be much nicer to use a Unicode literal."},"comment":{"url":"https://api.github.com/repos/pallets/jinja/issues/comments/210612226","html_url":"https://github.com/pallets/jinja/issues/392#issuecomment-210612226","issue_url":"https://api.github.com/repos/pallets/jinja/issues/392","id":210612226,"user":{"login":"byoungb","id":1561153,"avatar_url":"https://avatars.githubusercontent.com/u/1561153?v=3","gravatar_id":"","url":"https://api.github.com/users/byoungb","html_url":"https://github.com/byoungb","followers_url":"https://api.github.com/users/byoungb/followers","following_url":"https://api.github.com/users/byoungb/following{/other_user}","gists_url":"https://api.github.com/users/byoungb/gists{/gist_id}","starred_url":"https://api.github.com/users/byoungb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/byoungb/subscriptions","organizations_url":"https://api.github.com/users/byoungb/orgs","repos_url":"https://api.github.com/users/byoungb/repos","events_url":"https://api.github.com/users/byoungb/events{/privacy}","received_events_url":"https://api.github.com/users/byoungb/received_events","type":"User","site_admin":false},"created_at":"2016-04-15T19:42:59Z","updated_at":"2016-04-15T19:42:59Z","body":"+1"}}