web.py markdown 全局名称 'markdown' 未定义
web.py markdown global name 'markdown' is not defined
我试图在 web.py 中将 markdown 与 Templetor 一起使用,但我无法弄清楚我缺少什么
文档在这里http://webpy.org/docs/0.3/templetor#builtins
import markdown
t_globals = {
'datestr': web.datestr,
'markdown': markdown.markdown
}
render = web.template.render(globals=t_globals)
class Blog:
def GET(self, post_slug):
""" Render single post """
post = BlogPost.get(BlogPost.slug == post_slug)
render = web.template.render(base="layout")
return render.post({
"blogpost_title": post.title,
"blogpost_content": post.content,
"blogpost_teaser": post.teaser
})
这是我尝试在 post.html 模板中使用 markdown 的方法
$def with (values)
$var title: $values['blogpost_title']
<article class="post">
<div class="post-meta">
<h1 class="post-title">$values['blogpost_title']</h1>
</div>
<section class="post-content">
<a name="topofpage"></a>
$:markdown(values['blogpost_content'])
</section>
但是我遇到了这个异常
type 'exceptions.NameError' at
/blog/he-ll-want-to-use-your-yacht-and-i-don-t-want-this-thing-smelling-like-fish/
global name 'markdown' is not defined
您是 re-initializing render
,一次在全局范围设置 globals
中,一次在 Blog.GET
设置 base
中。只做一次!
我试图在 web.py 中将 markdown 与 Templetor 一起使用,但我无法弄清楚我缺少什么
文档在这里http://webpy.org/docs/0.3/templetor#builtins
import markdown
t_globals = {
'datestr': web.datestr,
'markdown': markdown.markdown
}
render = web.template.render(globals=t_globals)
class Blog:
def GET(self, post_slug):
""" Render single post """
post = BlogPost.get(BlogPost.slug == post_slug)
render = web.template.render(base="layout")
return render.post({
"blogpost_title": post.title,
"blogpost_content": post.content,
"blogpost_teaser": post.teaser
})
这是我尝试在 post.html 模板中使用 markdown 的方法
$def with (values)
$var title: $values['blogpost_title']
<article class="post">
<div class="post-meta">
<h1 class="post-title">$values['blogpost_title']</h1>
</div>
<section class="post-content">
<a name="topofpage"></a>
$:markdown(values['blogpost_content'])
</section>
但是我遇到了这个异常
type 'exceptions.NameError' at /blog/he-ll-want-to-use-your-yacht-and-i-don-t-want-this-thing-smelling-like-fish/ global name 'markdown' is not defined
您是 re-initializing render
,一次在全局范围设置 globals
中,一次在 Blog.GET
设置 base
中。只做一次!