I get the same problem (UndefinedError: 'uri_for' is undefined) with my
coto-boilerplate website.
It happens on the first uri_for call in a template. I had canonical links
in the header which called uri_for but caused errors so I removed them, but
now the errors are happening in my navbar html.
uri_for is defined in basehandler.py like so:
def jinja2_factory(app):
j = jinja2.Jinja2(app)
j.environment.filters.update({
# Set filters.
# ...
})
j.environment.globals.update({
# Set global variables.
'csrf_token': generate_csrf_token,
'uri_for': webapp2.uri_for,
'getattr': getattr,
})
j.environment.tests.update({
# Set test.
# ...
})
return j
The error happens randomly, but pretty much kills the instance until I
restart.
Here is a stack trace from the error when uri_for was used in a canonical
link.
File "/base/data/home/runtimes/python27/python27_lib/
versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in __call__ rv =
self.router.dispatch(request, response)
File "/base/data/home/runtimes/python27/python27_lib/
versions/third_party/webapp2-2.5.2/webapp2.py", line 1278, in
default_dispatcher return route.handler_adapter(request, response)
File "/base/data/home/runtimes/python27/python27_lib/
versions/third_party/webapp2-2.5.2/webapp2.py", line 1102, in __call__
return handler.dispatch()
File "/base/data/home/apps/s~<site>/1-1.373006929445588669/
boilerplate/lib/basehandler.py", line 88, in dispatch
webapp2.RequestHandler.dispatch(self)
File "/base/data/home/runtimes/python27/python27_lib/
versions/third_party/webapp2-2.5.2/webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
File "/base/data/home/runtimes/python27/python27_lib/
versions/third_party/webapp2-2.5.2/webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File
"/base/data/home/apps/s~<site>1/1-1.373006929445588669/boilerplate/handlers.py",
line 1526, in get return self.render_template('home.html', **params)
File "/base/data/home/apps/s~<site>/1-1.373006929445588669/
boilerplate/lib/basehandler.py", line 320, in render_template
self.response.write(self.jinja2.render_template(filename, **kwargs))
File "/base/data/home/runtimes/python27/python27_lib/
versions/third_party/webapp2-2.5.2/webapp2_extras/jinja2.py", line 158, in
render_template return self.environment.get_template(
_filename).render(**context)
File "/base/data/home/runtimes/python27/python27_lib/
versions/third_party/jinja2-2.6/jinja2/environment.py", line 894, in render
return self.environment.handle_exception(exc_info, True)
File "boilerplate/templates/home.html", line 1, in top-level template code
{% extends base_layout %}
File "boilerplate/templates/base.html", line 40, in top-level template code
File "boilerplate/templates/home.html", line 6, in block "canonical" {%
block canonical %}{{ uri_for("home") }}{% endblock %}
UndefinedError: 'uri_for' is undefined
On Tuesday, January 14, 2014 12:13:42 AM UTC-8, Roninio wrote:
>
>
> Vinny, Thanks for your answer. I have looked into the suggestion but can
> find difference with my code.
>
> I get the error only when i upload a new code to the app engine. If i
> restarted it manually it works.
>
> Error 500: 'uri_for' is undefined
>
>
> any ideas? Thanks
>
>
>
>
> On Tuesday, January 14, 2014 6:14:17 AM UTC+2, Vinny P wrote:
>>
>> On Sun, Jan 12, 2014 at 4:30 AM, Ronen Azachi <[email protected]> wrote:
>>
>>> having same problem. I am using the boilerplate "
>>> https://github.com/coto/gae-boilerplate"
>>> did you resolve this issue?
>>>
>>> On Monday, July 16, 2012 10:34:35 AM UTC+3, Thomas Marban wrote:
>>>>
>>>> Ever since including webapp2.uri_for in my webapp2_extras.jinja2 config
>>>> via
>>>>
>>>> 'globals': { 'uri_for' : webapp2.uri_for },
>>>>
>>>> I'm getting an undefined error every time I change a python file and
>>>> load the app for the first time. It won't come up on subsequent requests.
>>>> Also tried to inject it into globals via a Jinja2 factory but same result.
>>>> Any hints?
>>>>
>>>> UndefinedError: 'uri_for' is undefined
>>>>
>>>>
>>
>> The fix is to insert *uri_for* as a global in some manner. There's many
>> ways to do this, but you can try the strategy outlined here:
>> http://stackoverflow.com/questions/7081250/webapp2-jinja2-how-can-i-get-uri-for-working-in-jinja2-views
>>
>>
>>
>> -----------------
>> -Vinny P
>> Technology & Media Advisor
>> Chicago, IL
>>
>> App Engine Code Samples: http://www.learntogoogleit.com
>>
>>
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-appengine.
For more options, visit https://groups.google.com/groups/opt_out.