【发布时间】:2016-11-28 19:17:27
【问题描述】:
我将 web.py 模板用于我的项目并使用 render('templates', base="") 我将基本布局与页面特定布局(简化)结合起来。
view.py
render = web.template.render('templates',base='layout')
return render.index()
共享布局文件
layout.html
$def with (content)
<html>
<head>
<title>$content.title</title>
</head>
<body>
$:content
</body>
</html>
页面特定模板
index.html
$def with (values)
$var title: Hello Kitty
<p>Hello $values, how are you doin?</p>
我正在寻找的解决方案是如何实现以下
login.html
$def with (values)
$var title: Enter credentials
<form>
<p><input type="text" name="user_name"></p>
<p><input type="password" name="user_pwd"></p>
<p><button type="submit">Open the gates</button></p>
</form>
$block_begin
<script>
// When the form is submitted, check the required fields and inform user
// if any data is missing or looks weird
</script>
$block_end
</body>
</html>
我的问题是,如何将脚本添加到 login.html 模板而不是 index.html 模板?我对必须将所有 JS 逻辑添加到所有页面不感兴趣,我想添加这个 $block_begin/$block_end 以便它像这样出现在 layout.html 的底部
layout.html
$def with (content)
<html>
<head>
<title>$content.title</title>
</head>
<body>
$:content
$block_begin
$block_end
</body>
</html>
$block_begin/$block_end 只是我想出的更好地解释自己的东西。
【问题讨论】: