我正在构建一个具有下面结构的应用程序。在这一点上,它是一个非常简单的应用程序。但是,我无法弄清楚如何渲染index.html。我不确定我错过了什么:
/application
--config.py
--setup.py
--__init__.py
--/app
----/__init__.py
--/controllers
----/test.py
----/__init__.py
--/views
----/static
----/templates
------/index.html
应用/ __初始化__。PY
from flask import Flask
from application import config
class App(Flask):
def __init__(self):
super(App, self).__init__(__name__)
self.config.from_object('application.config')
控制器/ test.py
from flask import Blueprint, render_template
from flask.views import MethodView
from application.app import App
from application import config
test = Blueprint(
'test',
__name__,
template_folder=config.TEMPLATES,
)
class Index(MethodView):
def get(self):
...
return render_template('index.html', error=error)
test.add_url_rule("/", view_func=Index.as_view('index'))
setup.py
from flask.ext.script import Manager, Command
from application import config
from application.app import App
app = App()
manager = Manager(app)
class InitApplication(Command):
def execute(self):
...
manager.add_command('init', Init())
if __name__ == "__main__":
manager.run()
config.py
import os
TEMPLATES = "{}/application/views/templates/".format(os.getcwd())
任何指导都会有所帮助。
答案 0 :(得分:1)
对于Flask对象,蓝图需要registered。
from flask import Flask
from application import config
class App(Flask):
def __init__(self):
super(App, self).__init__(__name__)
self.config.from_object('application.config')
from application.controllers.test import test
self.register_blueprint(test)