flask-classy
flask-classy copied to clipboard
Blueprint template not found
Thank for flask-classy. I am coming from php codeigniter and flask-classy helped me very much.
I have a problem. i am trying to do that example http://flask.pocoo.org/docs/0.10/blueprints/#templates .
My application structure
/app
/modules
/module_test
controllers.py
/templates
/test
index.html
/templates
/app/modules/module_test/controllers.py
test = Blueprint('test', "mest", template_folder='templates' )
class TestController(FlaskView):
def index(self):
return render_template( "test/index.html", **self.viewData )
TestController.register(test)
When i tried blueprint without flask-classy it worked, but when i tried with flask-classy it did not work , the error is "jinja2.exceptions.TemplateNotFound TemplateNotFound: test/index.html". i put index.html in /app/templates/test/index.html and i tried with flask classy it worked.
i want to put template files in blueprint that "/app/modules/module_test/templates". How can i solve this problem?
I did this change
from
test = Blueprint('test', "mest", template_folder='templates' )
to
test = Blueprint('test', "mest", template_folder='app/modules/module_test/templates' )
it worked.
But Flask documentation says that:
admin = Blueprint('admin', __name__, template_folder='templates')
As for static files, the path can be absolute or relative to the blueprint resource folder. The template folder is added to the searchpath of templates but with a lower priority than the actual application’s template folder. That way you can easily override templates that a blueprint provides in the actual application.
So if you have a blueprint in the folder yourapplication/admin and you want to render the template 'admin/index.html' and you have provided templates as a template_folder you will have to create a file like this: yourapplication/admin/templates/admin/index.html.
admin = Blueprint('admin', name, template_folder='templates')
You are not following the documentation, you need to actually pass __name__
into Blueprint
@danielchatfield thanks. it worked