使用 url_for 触发 AttributeError: 'thread._local'对象没有属性“映射器”;
我试图在带有金字塔的 mako 模板中使用 url_for (使用书籍示例):
${h.url_for(controller='formtest',action='submit')}
当我这样做时,我收到此错误:
AttributeError: 'thread._local' object has no attribute 'mapper'
我安装了路由并将其放入我的 helpers.py 文件中:
import webhelpers.html.tags as tags
from routes import url_for
谷歌搜索错误,我读到 url_for Pylons 已被弃用。金字塔也是如此吗?如果是这样,我应该使用什么?
I am attempting to use url_for inside of a mako template with pyramid (using a book example):
${h.url_for(controller='formtest',action='submit')}
When I do, I get this error:
AttributeError: 'thread._local' object has no attribute 'mapper'
I installed routes and put this in my helpers.py file:
import webhelpers.html.tags as tags
from routes import url_for
Googling the error, I read that url_for has been deprecated for Pylons. Is this true for Pyramid too? If so, what should I be using?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确定您使用的是金字塔吗? 您发布的所有内容都是关于 Pylons 而不是 Pyramid。它们是非常不同的框架。
假设您使用 Pylons,
url_for
已被弃用。您应该使用从from pylons import url
导入的url
全局变量。Are you sure you're using Pyramid? Every thing that you have posted is about Pylons and not Pyramid. They are very different frameworks.
Assuming you are using Pylons,
url_for
was deprecated. You should instead be using theurl
global variable which is imported fromfrom pylons import url
.