In jinja2 on Google App Engine, how can I (easily) build a URL based on a route name with arguments? -


if construct jinja environment follows:

jinja_environment = jinja2.environment (     loader=jinja2.filesystemloader ((os.path.dirname (__file__), 'templates')), extensions=[]) jinja_environment.globals['url_for'] = webapp2.uri_for 

in templates, can build simple urls route name when route not define arguments:

{{ url_for('user_home') }} 

however, when route contains argument defined string such /invoice/<:\d+>, unable pass arguments. calling in following ways fails, keyerror "missing argument "0" build uri.":

{{ url_for('invoice') }} {{ url_for('invoice', args=['123']) }} {{ url_for('invoice', kwargs={'__0__':'123'}) }} {{ url_for('invoice',_request=none, args=['123'],kwargs={'__0__':'123'}) }} 

existing examples seem out of date--at least haven't been able make them work. missing?

route('/invoice/<invoice_id>/', handler=invoice_handler, invoice_id='something')

{{ url_for('invoice', invoice_id=123) }}

you can try above, jinja expecting named parameter defined handler.


Comments