Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blueprint template not found #66

Open
serkandaglioglu opened this issue Sep 27, 2014 · 3 comments
Open

Blueprint template not found #66

serkandaglioglu opened this issue Sep 27, 2014 · 3 comments

Comments

@serkandaglioglu
Copy link

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?

@serkandaglioglu
Copy link
Author

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.

@danielchatfield
Copy link

admin = Blueprint('admin', name, template_folder='templates')

You are not following the documentation, you need to actually pass __name__ into Blueprint

@serkandaglioglu
Copy link
Author

@danielchatfield thanks. it worked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants