質問

is there any way to print html code on GAE webapp?

for k, v in menubar.iteritems():
if(re.search(v, self.request.path)):
  menustring += '<li class="current"><a href="'+v+'">'+k+'</a></li>'
else:
  menustring += '<li><a href="'+v+'">'+k+'</a></li>'

print on template:

<ul>
  {{ menustring }}      
</ul>

it shows &lt &gt instead of < >

役に立ちましたか?

解決

HTML tags (or rather, <) are automatically escaped by Django templates to prevent cross site scripting vulnerabilities. You can use the safe filter (eg {{menustring|safe}}) to prevent escaping.

You almost certainly shouldn't be using this here, though - you should instead pass in the list of groups into the template, and iterate over them there. This ensures that individual items are escaped where required, and also avoids putting template rendering logic into your code.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top