Python escape usage in django templates by GAE

Chris Rebert clp2 at rebertia.com
Thu Mar 3 03:11:22 EST 2011


On Wed, Mar 2, 2011 at 11:50 PM, Niklasro <niklasro at gmail.com> wrote:
> Hi
> I got problems with escape displaying like junk when upgrading from
> django 0.96 to 1.2 with google app engine.
> The code is
>
>     # let user choose authenticator
>        for p in openIdProviders:
>            p_name = p.split('.')[0] # take "AOL" from "AOL.com"
>            p_url = p.lower()        # "AOL.com" -> "aol.com"
>            loginmsg = loginmsg + '<a href="%s">%s</a> ' % ( #'','')
>                   users.create_login_url(federated_identity=p_url),
> p_name)
>        loginmsg = loginmsg + '<a href=\"%s\">%s</a>' %
> ('login',_("Log in"))
>
> And the output is strange. View source show this:
>
> <ul><li><a href="ai">Add</a></li><li><a href="li">03 Mar</a></li>
>
> <li>Log in<a href="google.com">Google</a> <a
> href="google.com">Yahoo</a> <a
> href="google.com">MySpace</a> <a
> href="google.com">AOL</a> <a
> href="login">Log in</a></li>
>
> </ul>
>
> Can you make ad advice how to proceed? Many thanks,

IIRC, at some point after v0.96, Django made
HTML-character-entity-escaping of values in templates the default
behavior; your code assumes the opposite, hence your excessive
escaping problem. I'm sure there's a way to indicate that certain
values should be treated literally and not get HTML-escaped.

Check the transition docs / release notes, and/or try asking on the
django-specific mailing list
(http://groups.google.com/group/django-users )
(You should probably ask there first with any future Django questions too.)

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list