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

Bizarre __unicode__()-related issue #41

Open
evildmp opened this issue Dec 15, 2014 · 1 comment
Open

Bizarre __unicode__()-related issue #41

evildmp opened this issue Dec 15, 2014 · 1 comment

Comments

@evildmp
Copy link

evildmp commented Dec 15, 2014

I've used {{ item|typogrify }} without issue a billion times if not more, but today I discovered a problem that has me completely baffled.

Here are two absolutely identical model methods:

def blah(self):
    return self.destination_content_object.__unicode__()

def __unicode__(self):
    return self.destination_content_object.__unicode__()

Now if in my template I do {{ item.blah|typogrify }}, it'll work perfectly. If I do the same with {{ item|typogrify }}, there's a template error.

This is the weird thing:

  • without the typogrify filter, the model's __unicode__() gets called
  • with the typogrify filter, the model's it doesn't

And when it doesn't get called, what happens is that the typogrify tags, instead of receiving the unicode that they expect, receive a model object that they naturally choke on.

So it seems to me that typogrify is somehow intercepting the contents of the template before Django is able to turn the {{ item }} into unicode, if that makes sense.

(Just to add to the complexity of this, the template belongs to a django CMS plugin, which has a habit of swallowing up errors and making them harder to debug.)

@evildmp
Copy link
Author

evildmp commented Dec 15, 2014

Problem identified: {% autoescape off %} was the cause.

On the other hand, I do find that I need to turn off autoescaping all over the place in order to get typogrify to trigger. It's not really clear to me what is preventing it from doing so though.

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

No branches or pull requests

1 participant