Forums

bootstrap/jinja2 error

Hi,

I'm trying to use bootstrap templates for my site, and I keep getting the following error:

jinja2.exceptions.TemplateNotFound: bootstrap/base.html

Now, here's the weird bit: I made sure to have the path fully defined in my "{% extends %} " for the base.html file. I verified the installation, and I've tried changing the path and moving around files in bash, but I still get the same error. It's bad enough that I'm resorting to this forum, and so any insights are appreciated.

Hi pv,

I just sent you an email about this, but here's something in case other people come here having searched for something similar to this.

If you're using Flask, and in your template you have

{% extends "bootstrap/base.html"  %}

...then you need a file called base.html inside a bootstrap subdirectory of your templates directory, like this:

mysite
├── flask_app.py
└── templates
    ├── bootstrap
    │   └── base.html
    └── mytemplate.html

Thank you, Giles! It worked.

Excellent! Thanks for confirming :-)

Doesn't work for me. My python code is visible on the webpage and also does not inherit my main page.

You should provide more details than that for other people to help you.

Hi, so, I don't have the error after I created an empty base.html file in my templates folder but now all my pages are blank. Should I be putting something in that bootstrap base.html? If so, what?

what else do you have in your template? can you show us a sample one?

Here is my base template, and the rest of my project: https://github.com/Mandawi/ToWear/blob/master/templates/base.html. I am not supposed to need to have a bootstrap folder with a base.html. The base.html is inherited from the flask_bootstrap package, as shown here: https://pythonhosted.org/Flask-Bootstrap/basic-usage.html.

If you're seeing your Python code on the page that is served, as you said in your original post, that suggests to me that you were no rendering the template or perhaps you were somehow serving the template directly as a static file and not through your flask app.

I don't think the original advice (to create bootstrap/base.html) applied to your situation and now the creation of the bootstrap/base.html file is hiding the bootstrap/base.html file that is supposed to be provided by flask bootstrap. delete the bootstrap directory, reload your web app and let us know what the result is.

It works, now. I had to rename my variable to "bootstrap". Doing "BS = Bootstrap(app)" instead of "bootstrap = Bootstrap(app)" caused the mishap.

Interesting. Thanks for letting us know.

i tried everything on the above and still the bootstrap wont load

i have created a virtual environment and installed all packages in it....it also contains the flask_bootstrap package... I also checked to make sure that it has the base.html and other html files inside the templates in bootstrap directory.. i also added the virtual environment where it was asked in the web page ....what did i do wrong

What is the exact error message that you're getting in your websites error log? There's a link to that log on the "Web" page, and the most recent error will be at the bottom of the file.