Aja*_*man 13 html python templates web.py
我正在处理类似维基百科的项目.我可以使用markdown将文本文件转换为html代码.我的问题是,我想在html文件中呈现这个html代码.这是我的代码,
class articles:
def GET(self):
form_name=web.input()
article_name=form_name.page
article_file_path=os.path.join('articles',article_name)
fp = open(article_file_path,'rU')
text = fp.read()
body = markdown2.markdown(text)
return render.article_files(article_name, body)
Run Code Online (Sandbox Code Playgroud)
我将article_name和body(html代码)传递给article_files.html.身体看起来像,
<h1>Hai</h1>
<p>Welcome<em>Ajay</em></p>
Run Code Online (Sandbox Code Playgroud)
问题是,身体显示原样.这就是html代码在屏幕上打印出来的所有标签.我想渲染这个HTML代码(正文),
海
欢迎 Ajay
我的HTML文件是:
$def with(title,content)
<html>
<head>
<title>$title</title>
</head>
<body>
<form name="form" method="GET">
$content
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
Hel*_*lgi 12
默认情况下,web.py模板中的HTML转义处于启用状态.要将其关闭,请在冒号前添加变量名称:
<form name="form" method="GET">
$:content
</form>
Run Code Online (Sandbox Code Playgroud)
确保潜在恶意用户无法将任意HTML提供给未转义的模板.