我正在學習燒瓶,並且對如何構造我的代碼有點困惑。所以我試圖擴展燒瓶主類如下:擴展燒瓶類作爲主要應用程序
from flask import Flask, ...
class App(Flask):
def __init__(self, import_name, *args, **kwargs):
super(App, self).__init__(import_name, *args, **kwargs)
請注意,我知道這可能是一個完全錯誤的方法。
所以,當我想啓動應用程序,我做的事:
app = App(__name__)
if __name__ == '__main__':
app.run()
這樣我可以爲了我在類的方法和途徑,但使用自裝飾時,問題是:
@route('/')
def home(self, context=None):
context = context or dict()
return render_template('home.html', **context)
這會產生一個錯誤unresolved reference 'route'
。我想這不是我應該構建應用程序的方式。我應該怎麼做,或者我如何解決這個錯誤?