pythonpyramid

Using url_for triggers AttributeError: 'thread._local' object has no attribute 'mapper'


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?


Solution

  • 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 the url global variable which is imported from from pylons import url.