public
Created

Template

  • Download Gist
gistfile1.pytb
Python traceback
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
Traceback (most recent call last):
File "/Users/DLC/.virtualenvs/b/lib/python2.7/site-packages/tornado/web.py", line 1021, in _stack_context_handle_exception
raise_exc_info((type, value, traceback))
File "/Users/DLC/.virtualenvs/b/lib/python2.7/site-packages/tornado/stack_context.py", line 258, in _nested
yield vars
File "/Users/DLC/.virtualenvs/b/lib/python2.7/site-packages/tornado/stack_context.py", line 228, in wrapped
callback(*args, **kwargs)
File "/Users/DLC/.virtualenvs/b/lib/python2.7/site-packages/tornado/gen.py", line 382, in inner
self.set_result(key, result)
File "/Users/DLC/.virtualenvs/b/lib/python2.7/site-packages/tornado/gen.py", line 315, in set_result
self.run()
File "/Users/DLC/.virtualenvs/b/lib/python2.7/site-packages/tornado/gen.py", line 345, in run
yielded = self.gen.send(next)
File "/Users/DLC/Code/gkapps/b/handlers/route.py", line 135, in get
is_app=self.is_app)
File "/Users/DLC/.virtualenvs/b/lib/python2.7/site-packages/tornado/web.py", line 500, in render
html = self.render_string(template_name, **kwargs)
File "/Users/DLC/Code/gkapps/handlers/base.py", line 13, in render_string
return tornado.web.RequestHandler.render_string(self, template, **kwargs)
File "/Users/DLC/.virtualenvs/b/lib/python2.7/site-packages/tornado/web.py", line 607, in render_string
return t.generate(**namespace)
File "/Users/DLC/.virtualenvs/b/lib/python2.7/site-packages/tornado/template.py", line 261, in generate
return execute()
File "web/route_html.generated.py", line 429, in _execute
return _utf8('').join(_buffer) # web/base.html:0
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 27: ordinal not in range(128)
p.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#catch link and hashtags or @ mentions
_LINK_RE = re.compile(ur"([@#])([\w]+)")
 
def link_elements(text):
def make_link(m):
link_type = m.group(1)
if link_type == u'@':
link_type = u'/%s' % m.group(2)
else:
link_type = u'/tag/%s' % m.group(2)
return u'<a href="%s">%s</a>' % (link_type, m.group(0))
return _LINK_RE.sub(make_link, text)
 
return self.render("t.html", link_elements=link_elements)
t.html
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
{% extends "base.html" %}
 
 
{% block body %}
 
...
 
{% if len(comments) > 0 and (not is_app or show_comments) %}
<div class="comments">
{% for comment in comments %}
<a class="username" href="/{{ comment["user"]["username"] }}">{{ comment["user"]["username"] }}</a>
<p class="comment">{% apply link_elements %}{{ comment['textContent'] }} {% end %}</p>
{% end %}
</div>
{% end %}
 
...
 
{% end %}
 
{% end %}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.