python - 如何显示 Copyleft 符号?

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

最佳答案

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

关于python - 如何显示 Copyleft 符号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19621297/

相关文章:

jinja2 - 如何附加到字符串列表中的每个项目?

django - 如何在 Django 中制作可重用的模板?

python - 读取 csv 并插入数据库性能

python - 如何解决 TypeError : can only concatenate str (not "int") to str

python - 表示要存储在文本文件中的图形的最佳方式

android - 如何在 Android SyncAdapter 中使用 GWT-RequestFactory(总是出现 ValidationTool-Error)

python - 如何在我的 GAE 数据存储上实现搜索 API?

python - 清理 CSV——开始新行

python - Python 中的 Google App Engine 循环模型依赖项

html - 停止 jupyter notebook 在 pandas html 表输出中包装单元格内容