Jinja2 Template Not Found And Internal Server Error
Solution 1:
flask file structure
|-app
|--templates // where your html files must be in
|--static // where your js and css files must be in
|--.py files
|--other packages
Also jinja is enabled in your system, if you have already downloaded flask package.
Solution 2:
By default, Flask looks in the templates
folder in the root level of your app.
http://flask.pocoo.org/docs/0.10/api/
template_folder – the folder that contains the templates that should be used by the application. Defaults to 'templates' folder in the root path of the application.
So you have some options,
- rename
template
totemplates
supply a
template_folder
param to have yourtemplate
folder recognised by the flask app:app = Flask(__name__, template_folder='template')
Flask expects the templates
directory to be in the same folder as the module in which it is created;
You'll need to tell Flask to look elsewhere instead:
app = Flask(__name__, template_folder='../pages/templates')
This works as the path is resolved relative to the current module path.
You cannot have per-module template directories, not without using blueprints. A common pattern is to use subdirectories of the templates
folder instead to partition your templates. You'd use templates/pages/index.html
, loaded with render_template('pages/index.html')
, etc.
Post a Comment for "Jinja2 Template Not Found And Internal Server Error"