4

My structure for files is this.

-App
    -services
        - __init__.py
        - app_file.py
    -templates
        - hello.html

Inside app_file.py, I've got

@app.route('/')
def hello():
    return render_template('hello.html')

I know I have at least got a working "hello world" program, because this much worked

@app.route('/')
def hello():
    return 'Hello World'

However, when I attempt the templated html, I get this error.

jinja2.exceptions.TemplateNotFound

As I said, I'm almost positive it is something with my file structure, so I posted only what I feel is necesary to determine if I am right or not, but will post more upon request. Help please?

Zack
  • 13,454
  • 24
  • 75
  • 113

1 Answers1

3

templates should be a subfolder of where the services package, or you need to set a custom template_folder argument when creating the Flask() app object:

app = Flask(__name__, template_folder='../templates')
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • do you know what the difference between "from flask import Module" vs "from flask import Flask" is? I am using the "Module" import which looks to be about the same, but it isn't working as expected " got an unexpected keyword argument 'template_folder'" – Zack Mar 03 '14 at 17:47
  • 1
    A `Module` is the predecessor of [Blueprints](https://flask.readthedocs.org/en/latest/blueprints/); these have been deprecated since Flask 0.7 and under the hood they are now just Blueprints with a hardcoded `template_folder` argument. Use a Blueprint instead. – Martijn Pieters Mar 03 '14 at 17:52
  • See the [upgrading to 0.7 documentation](https://flask.readthedocs.org/en/latest/upgrading/#blueprint-support) as well. – Martijn Pieters Mar 03 '14 at 17:54
  • Saying cannot import name Blueprint.. is an install necesary, or some other form of upgrade? – Zack Mar 03 '14 at 18:10
  • If you have a setup with Flask 0.6 or older installed, you cannot use Blueprints. You'd either have to upgrade your setup, or stick to Modules. If you choose to stick with the older Flask version, you'll *have* to move the `templates` directory as that version of Flask doesn't support setting a different directory. – Martijn Pieters Mar 03 '14 at 18:14