2

我使用 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) 时,它会给出一个 ?(问号)符号,但没有错误。

4

4 回答 4

3

©我建议将模板中的版权符号替换为&copy;

于 2013-10-31T05:48:40.897 回答
1

Unicode 中只有一个近似值。
显示.png 文件并根据需要使用属性调整大小。

于 2013-10-28T22:18:57.930 回答
0

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

 # coding=utf-8

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

于 2013-10-27T17:57:32.447 回答
0

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

>>> print('\U0001f12f')

问候。

于 2020-01-29T18:18:21.533 回答