视图函数
<span class="hljs-meta">@app.errorhandler(404)</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">page_not_found</span><span class="hljs-params">(e)</span>:</span>
<span class="hljs-keyword">return</span> render_template(<span class="hljs-string">'error.html'</span>,title=<span class="hljs-string">'404NOTFOUND'</span>, info=e)
<span class="hljs-meta">@app.errorhandler(500)</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">page_not_found</span><span class="hljs-params">(e)</span>:</span>
<span class="hljs-keyword">return</span> render_template(<span class="hljs-string">'error.html'</span>,title=<span class="hljs-string">'500ERROR'</span>, info=e)
定制模板
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{ title }}</title>
</head>
<body>
<h2>{{ err }}</h2>
</body>
</html>
locals
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">index</span><span class="hljs-params">()</span>:</span>
a = <span class="hljs-number">1</span>
b = <span class="hljs-number">2</span>
<span class="hljs-keyword">return</span> render_template(<span class="hljs-string">'boot_index.html'</span>,**locals())
将字典变成关键字 参数
def index():
return render_template('boot_index.html',**{'a':1,'b':2})
原始传参
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">index</span><span class="hljs-params">()</span>:</span>
<span class="hljs-keyword">return</span> render_template(<span class="hljs-string">'boot_index.html'</span>,a=<span class="hljs-number">1</span>,b=<span class="hljs-number">2</span>)
将参数写在字典中
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">index</span><span class="hljs-params">()</span>:</span>
<span class="hljs-keyword">return</span> render_template(<span class="hljs-string">'boot_index.html'</span>,val={<span class="hljs-string">'a'</span>:<span class="hljs-number">1</span>,<span class="hljs-string">'b'</span>:<span class="hljs-number">2</span>})