擅长:python、mysql、java
<p>您可以在<code>__init__</code>方法的上下文中定义函数。然后,要使函数能够正常调用,请将<code>home</code>成员设置为它的值。在</p>
<pre><code>class MyClass:
def __init__(self):
self.server = Flask(__name__)
# This is indented at __init__'s level, so a new instance of the function
# is defined every time __init__ runs. That means a new instance
# is defined for each instance of the class, and so it can be wrapped with
# the instance's "self" value.
@self.server.route('/')
def home_func():
return '<h1>Success</h1>'
# Then, you make it an object member manually:
self.home = home_func
</code></pre>