sysr-q / flask-themes2

Easily theme your Flask app. (Flask-Themes with Flask>=0.6 support!)
Other
19 stars 14 forks source link

TemplateNotFoundError althought template should be there #7

Closed Cereal2nd closed 9 years ago

Cereal2nd commented 9 years ago
>>> from jinja2 import FileSystemLoader
>>> b = FileSystemLoader('/home/cereal/domogik/src/domogik/admin/themes/default/templates')
>>> b.list_templates()
['account_edit.html', 'accounts.html', 'accounts_edit.html', 'base/base.html', 'base/nav.html', 'base/wtf.html', 'client.html', 'client_config.html', 'client_detected.html', 'client_device_edit.html', 'client_device_new.html', 'client_device_new_wiz.html', 'client_devices.html', 'client_menu.html', 'client_sensor.html', 'clients.html', 'configuration.html', 'index.html', 'login.html', 'orphans.html', 'person_edit.html', 'persons.html', 'rest.html', 'scenario.html', 'scenario_edit.html']

So jinja2 finds the templates in the directory.

now in my application i get the following

/home/cereal/domogik/src/domogik/admin/themes/default/templates
2015-01-22 20:29:40,395 domogik.admin.application ERROR Exception on /accounts [GET]
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python2.7/dist-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python2.7/dist-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/local/lib/python2.7/dist-packages/flask_login.py", line 758, in decorated_view
    return func(*args, **kwargs)
  File "/home/cereal/domogik/src/domogik/admin/views/account.py", line 33, in accounts
    mactive='auth'
  File "/home/cereal/domogik/src/domogik/admin/application.py", line 77, in render_template
    return render_theme_template('default', template, **context)
  File "/usr/local/lib/python2.7/dist-packages/flask_themes2/__init__.py", line 132, in render_theme_template
    return render_template(template_name, **context)
  File "/usr/local/lib/python2.7/dist-packages/Flask-0.10.1-py2.7.egg/flask/templating.py", line 127, in render_template
    return _render(ctx.app.jinja_env.get_or_select_template(template_name_or_list),
  File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 830, in get_or_select_template
    return self.get_template(template_name_or_list, parent, globals)
  File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 791, in get_template
    return self._load_template(name, self.make_globals(globals))
  File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 765, in _load_template
    template = self.loader.load(self, name, globals)
  File "/usr/lib/python2.7/dist-packages/jinja2/loaders.py", line 113, in load
    source, filename, uptodate = self.get_source(environment, name)
  File "/usr/local/lib/python2.7/dist-packages/Flask-0.10.1-py2.7.egg/flask/templating.py", line 64, in get_source
    raise TemplateNotFound(template)
TemplateNotFound: accounts.html
ERROR:domogik.admin.application:Exception on /accounts [GET]

and this is my render method

def render_template(template, **context):
    p = ThemeManager(app, app_identifier='domogik-admin')
    print p.themes['default'].templates_path
    return render_theme_template('default', template, **context)

But still i get a templateNotFOundError, althought its there

Cereal2nd commented 9 years ago

note, for some templates it works perfectly, for others that are in the same dir it does not work

sysr-q commented 9 years ago

Can you give an example of template files it works for and those it won't? It seems odd that you'd be able to use some templates and not others, even if they're in the same directory.

Cereal2nd commented 9 years ago

ticket can be closed, i solved it.

i had template A this includes template B and template B includes Template C

for the include of template C i missed the theme(c.html) part, so i had the regular include.

because of this template C was not found (what is corect), but the error i got is that template A was not found ...

sysr-q commented 9 years ago

Ah, good old deceptive error messages. No problem.