0

I just added flask-security to my flask project. It works locally, but reports this error on OpenShift:

TemplateAssertionError: no filter named 'urlencode'

I don't know if it is some wrong library version, or how to debug this. This is my setup.py package list:

install_requires=['Flask==0.10.1',
                    'SQLAlchemy==0.9.8',
                    'Flask-SQLAlchemy==2.0',
                    'Flask-Security==1.7.4',
                    'Werkzeug==0.9.5',
                    'blinker==1.3',
                    'Flask-Login==0.2.11',
                    'Flask-Mail==0.9.1',
                    'Flask-Principal==0.4.0',
                    'Flask-Script==2.0.5',
                    'Flask-WTF==0.10.3',
                    'itsdangerous==0.24',
                    'passlib==1.6.2'

  ]
Ognjen
  • 2,508
  • 2
  • 31
  • 47

2 Answers2

1

The urlencode filter was added to jinja in v2.7. But GAE only supports v2.6. Changing the version to "latest" in my app.yaml still runs with 2.6 (notice the python27_lib/versions/third_party/jinja2-2.6/jinja2/environment.py path):

...
 File "/base/data/home/apps/s~healthier-staging/1.386037228785871893/lib/flask/templating.py", line 128, in render_template
context, ctx.app)
  File "/base/data/home/apps/s~healthier-staging/1.386037228785871893/lib/flask/templating.py", line 110, in _render
    rv = template.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 "/base/data/home/apps/s~healthier-staging/1.386037228785871893/lib/flask_security/templates/security/_menu.html", line 4, in template
<li><a href="{{ url_for_security('login') }}{% if 'next' in request.args %}?next={{ request.args.next|urlencode }}{% endif %}">Login</a></li>
TemplateAssertionError: no filter named 'urlencode'`

I fixed this by adding a simple filter (copying the code that was added to jinja) manually:

def do_urlescape(value):
    """Escape for use in URLs."""
    return urllib.quote(value.encode('utf8'))
app.jinja_env.globals['urlencode'] = do_urlescape
Lane Rettig
  • 6,640
  • 5
  • 42
  • 51
0

I have solved this, by doing 'pip freeze' on my local machine, and copying libraries to setup.py one by one. Though I'm still not sure which one produced an error, probably wrong version of jinja2.

Ognjen
  • 2,508
  • 2
  • 31
  • 47