Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for use isinstance({}, dict) #12

Closed
wants to merge 1 commit into from
Closed

Fix for use isinstance({}, dict) #12

wants to merge 1 commit into from

Conversation

dongweiming
Copy link

I use flask-mako. But there was a problem, Below is my code:

app.py

from flask import Flask
from flask.ext.mako import MakoTemplates, render_template
from plim import preprocessor

app = Flask(__name__, template_folder="templates")
app.config['MAKO_TRANSLATE_EXCEPTIONS'] = False
app.config['MAKO_DEFAULT_FILTERS'] = ['decode.utf_8', 'h'] 
#app.config['MAKO_PREPROCESSOR'] = preprocessor

mako = MakoTemplates()
mako.init_app(app)

@app.route('/')
def index():
    s = 'a string'
    return render_template('test_no_plim.html', **locals())

if __name__ == '__main__':
    app.run(debug=True)

test_no_plim.html

<html>
  <body>
    <div>
      % if isinstance(s, dict):
      <a>dict</a>
      % else:
      <p>not dict</p>
    % endif
    </div>
  </body>
</html>

Display the following error when I visit http://127.0.0.1:5000/

TypeError

TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types

I found the reason is in jinja2 's commit 76c280bf5b2263a435e38e0b3612c23eb633ed79. It add a function that named dict interferes the built-in dict after update context from app.jinja_env.globals

@benselme benselme closed this Dec 7, 2014
@dongweiming
Copy link
Author

Why close it?

@benselme
Copy link
Owner

benselme commented Dec 8, 2014

Thanks for submitting it, but not useful enough for enough people. Besides
if we remove dict then why not remove other things as well ? I think we
should leave that as is. You should be able to find a workaround without
modifying flask-mako.

On Sun, Dec 7, 2014 at 7:09 PM, 小明 notifications@github.com wrote:

Why close it?


Reply to this email directly or view it on GitHub
#12 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants