【问题标题】:How do I display a copyleft symbol?如何显示 copyleft 符号?
【发布时间】:2013-11-06 10:17:03
【问题描述】:

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

【问题讨论】:

  • 请复制粘贴错误,不要在此处发布图片。
  • 你能用模板的相关部分更新问题吗?
  • @BurhanKhalid 刚刚更新

标签: python google-app-engine jinja2


【解决方案1】:

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

【讨论】:

  • 非常感谢,成功了!!但不能投票,因为我没有足够的声望。
【解决方案2】:

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

【讨论】:

    【解决方案3】:

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

     # coding=utf-8
    

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

    【讨论】:

    • 似乎不起作用。我什至尝试过:# -- coding: utf-8 -- 我使用 jinja2 模板引擎
    • @Chintan 但您是在 jinja2 模板中还是在脚本源代码中使用了 copyleft 符号?
    • @Chintan 我猜你的意思是:# -*- coding: utf-8 -*- 因为降价使它有点 italic :)
    • 我在模板中使用它,@Lipis 是的,我的意思是你说的。我无法以这种方式对其进行格式化。
    【解决方案4】:

    要在 Python 中打印 Copyleft 符号,只需这样做:

    >>> print('\U0001f12f')
    ?
    

    问候。

    【讨论】:

      猜你喜欢
      • 2012-07-29
      • 2014-05-17
      • 2020-07-13
      • 2018-03-12
      • 1970-01-01
      • 2018-07-10
      • 2019-06-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多