Python装饰器和烧瓶路由:我可以装饰函数调用还是只装饰函数定义?

Python装饰器和烧瓶路由:我可以装饰函数调用还是只装饰函数定义?,python,flask,routes,decorator,Python,Flask,Routes,Decorator,我有一条路线: @app.route('/') def index(): return render_template('index.html') 我可以在其他地方定义我的函数并修饰函数调用吗? from module import index @app.route('/') index() 我对decorators没有基本的了解,我也不确定标准行为是否有特定的内容,因此提前感谢您的澄清。在这种情况下,您不能修饰函数调用,但您可以定义需要调用的新函数: from modul

我有一条路线:

@app.route('/')
def index():
    return render_template('index.html')
我可以在其他地方定义我的函数并修饰函数调用吗?

from module import index    

@app.route('/')
index()

我对decorators没有基本的了解,我也不确定标准行为是否有特定的内容,因此提前感谢您的澄清。

在这种情况下,您不能修饰函数调用,但您可以定义需要调用的新函数:

from module import index    

@app.route('/')
def new_index()
    return index()
甚至很简单,正如@JoranBeasley所建议的:

app.route("/")(index)

或者只是
app.route(“/”,index)
@JoranBeasley如果路由带有参数会是什么样子?类似于
app.route('/profile/','profile',profile,profile\u id)
?不。。。就像普通的
app.route('/profile/',profile\u fn)
我有时会制作一个url.py来做这种事情。。。但后来我发现自己只是在重新创建django…我相信它需要是
app.route(“/”)(index)