如何显示copyleft符号?

时间:2013-10-27 17:49:13

标签: python google-app-engine jinja2

我使用Google AppEngine,Python 2.7和Jinja2模板。 我从维基百科尝试了这个https://en.wikipedia.org/wiki/Copyleft#Symbol。作为HTML,它在我的浏览器上打印正常。但是当我将它插入jinja2模板并尝试在我的GoogleAppEngine应用程序中进行测试时,它会产生500服务器错误。这是我在日志控制台上获得的堆栈跟踪的屏幕截图:

ERROR    2013-10-27 18:06:45,460 mycs253app.py:245] []

ERROR    2013-10-27 18:06:45,648 webapp2.py:1528] 'utf8' codec can't decode byte 0xa9 in position 1290: invalid start byte

Traceback (most recent call last):

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.3\webapp2.py", line 1511, in __call__

    rv = self.handle_exception(request, response, e)

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.3\webapp2.py", line 1505, in __call__

    rv = self.router.dispatch(request, response)

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.3\webapp2.py", line 1253, in default_dispatcher

    return route.handler_adapter(request, response)

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.3\webapp2.py", line 1077, in __call__

    return handler.dispatch()

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.3\webapp2.py", line 547, in dispatch

    return self.handle_exception(e, self.app.debug)

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.3\webapp2.py", line 545, in dispatch

    return method(*args, **kwargs)

  File "C:\Users\duck\Documents\GitHub\mycs253app\mycs253app.py", line 294, in get

    self.render_front_page(page_no)

  File "C:\Users\duck\Documents\GitHub\mycs253app\mycs253app.py", line 289, in render_front_page

    self.response.out.write(template.render(page))

  File "C:\Program Files (x86)\Google\google_appengine\lib\jinja2-2.6\jinja2\environment.py", line 894, in render

    return self.environment.handle_exception(exc_info, True)

  File "C:\Users\duck\Documents\GitHub\mycs253app\templates\main.html", line 1, in top-level template code

    {% extends "base.html" %}

UnicodeDecodeError: 'utf8' codec can't decode byte 0xa9 in position 1290: invalid start byte

ERROR    2013-10-27 18:06:45,677 wsgi.py:278] 

Traceback (most recent call last):

  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 266, in Handle

    result = handler(dict(self._environ), self._StartResponse)

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.3\webapp2.py", line 1519, in __call__

    response = self._internal_error(e)

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.3\webapp2.py", line 1511, in __call__

    rv = self.handle_exception(request, response, e)

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.3\webapp2.py", line 1505, in __call__

    rv = self.router.dispatch(request, response)

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.3\webapp2.py", line 1253, in default_dispatcher

    return route.handler_adapter(request, response)

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.3\webapp2.py", line 1077, in __call__

    return handler.dispatch()

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.3\webapp2.py", line 547, in dispatch

    return self.handle_exception(e, self.app.debug)

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.3\webapp2.py", line 545, in dispatch

    return method(*args, **kwargs)

  File "C:\Users\duck\Documents\GitHub\mycs253app\mycs253app.py", line 294, in get

    self.render_front_page(page_no)

  File "C:\Users\duck\Documents\GitHub\mycs253app\mycs253app.py", line 289, in render_front_page

    self.response.out.write(template.render(page))

  File "C:\Program Files (x86)\Google\google_appengine\lib\jinja2-2.6\jinja2\environment.py", line 894, in render

    return self.environment.handle_exception(exc_info, True)

  File "C:\Users\duck\Documents\GitHub\mycs253app\templates\main.html", line 1, in top-level template code

    {% extends "base.html" %}

UnicodeDecodeError: 'utf8' codec can't decode byte 0xa9 in position 1290: invalid start byte

INFO     2013-10-27 23:36:45,926 module.py:608] default: "GET / HTTP/1.1" 500 -

这是导致错误的模板(copyleft在最后):

<!DOCTYPE html>
<html>
<head>

  <link type="text/css" rel="stylesheet" href="/css/main.css" />

  <title>My Blog</title>

</head>

<body>

  <a href="/" class="main-title">
    My Blog
  </a>

  <div class="login-area">
    {% if user %}
      <a class="login-link" href="/newpost" >newpost</a>
      {{user.username}} (<a class="login-link" href="/logout">logout</a>)
    {% else %}
      <a class="login-link" href="/login">login</a>
      |
      <a class="login-link" href="/signup">signup</a>
    {% endif %}
  </div>

  <div id="content">
  {% block content %}
  {% endblock %}
  </div>


<!--Copyleft-->

<div style = "color: #333; font-size: 14px" >

<!--[if lte IE 8]><span style="filter: FlipH; -ms-filter: "FlipH"; display: inline-block;"><![endif]-->
<span style="-moz-transform: scaleX(-1); -o-transform: scaleX(-1); -webkit-transform: scaleX(-1); transform: scaleX(-1); display: inline-block;">
    ©
</span>
<!--[if lte IE 8]></span><![endif]-->

Chintan Pokhrel

</div>



</body>

</html>

此外,当我尝试打印ɔ(U + 0254)时,它会给出一个?(问号)符号,但没有错误。

3 个答案:

答案 0 :(得分:1)

Unicode中只有近似值 显示.png file并根据需要调整属性大小。

答案 1 :(得分:0)

如果您将符号直接添加到源代码中,请尝试将其添加到python文件的第一行

 # coding=utf-8

告诉解释器脚本使用utf-8编码。

答案 2 :(得分:0)

要在Python中打印Copyleft符号,只需执行以下操作:

>>> print('\U0001f12f')
?

致谢。

相关问题