擅长:python、mysql、java
<p><code>@</code>告诉Python用<code>app.route()</code>中定义的<em>decorator</em>装饰函数<code>index()</code>。</p>
<p>基本上,decorator是一个修改另一个函数行为的函数。作为一个玩具的例子,考虑一下这个。</p>
<pre><code>def square(func):
def inner(x):
return func(x) ** 2
return inner
@square
def dbl(x):
return x * 2
</code></pre>
<p>现在-调用<code>dbl(10)</code>将不会返回<code>20</code>,正如您所料,而是返回<code>400</code>(<code>20**2</code>)。</p>
<p><a href="http://simeonfranklin.com/blog/2012/jul/1/python-decorators-in-12-steps/" rel="nofollow noreferrer">This</a>是一个很好的步骤。装饰师讲解。</p>