Python escape usage in django templates by GAE

N

Niklasro

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&lt;a href=&quot;google.com&quot;&gt;Google&lt;/a&gt; &lt;a
href=&quot;google.com&quot;&gt;Yahoo&lt;/a&gt; &lt;a
href=&quot;google.com&quot;&gt;MySpace&lt;/a&gt; &lt;a
href=&quot;google.com&quot;&gt;AOL&lt;/a&gt; &lt;a
href=&quot;login&quot;&gt;Log in&lt;/a&gt;</li>

</ul>

Can you make ad advice how to proceed? Many thanks,
Niklas Rosenrantz
 
C

Chris Rebert

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&lt;a href=&quot;google.com&quot;&gt;Google&lt;/a&gt; &lt;a
href=&quot;google.com&quot;&gt;Yahoo&lt;/a&gt; &lt;a
href=&quot;google.com&quot;&gt;MySpace&lt;/a&gt; &lt;a
href=&quot;google.com&quot;&gt;AOL&lt;/a&gt; &lt;a
href=&quot;login&quot;&gt;Log in&lt;/a&gt;</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
 
N

Niklas RTZ

Wow, that really explains it superbly also pointing me to the right
place onwards. Many thanks Chris!

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&lt;a href=&quot;google.com&quot;&gt;Google&lt;/a&gt; &lt;a
href=&quot;google.com&quot;&gt;Yahoo&lt;/a&gt; &lt;a
href=&quot;google.com&quot;&gt;MySpace&lt;/a&gt; &lt;a
href=&quot;google.com&quot;&gt;AOL&lt;/a&gt; &lt;a
href=&quot;login&quot;&gt;Log in&lt;/a&gt;</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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,237
Latest member
AvivMNS

Latest Threads

Top