문제

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