ti-enxame.com

Erro jinja2.exceptions.TemplateNotFound

eu uso flask e recebi esse erro quando chamo esse URL: /login Aqui está o meu método de login:

@app.route('/login')
def login():
    if authenticateForPanel():
        return redirect(url_for("panel"))
    else:
        getParam = request.args.getlist('redirect_uri')
        if getParam:
            ref =getParam[0]
        else:
            ref="/panel"
        return render_template( themesDir + g.blogOptions['active_theme']+'/login.html', blogOptions = g.blogOptions, ref=ref )

E o rastreio:

Traceback (most recent call last):
  File "/Users/ozcan/Library/Python/2.7/lib/python/site-packages/flask/app.py", line 1701, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/ozcan/Library/Python/2.7/lib/python/site-packages/flask/app.py", line 1689, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/Users/ozcan/Library/Python/2.7/lib/python/site-packages/flask/app.py", line 1687, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/ozcan/Library/Python/2.7/lib/python/site-packages/flask/app.py", line 1360, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/ozcan/Library/Python/2.7/lib/python/site-packages/flask/app.py", line 1358, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/ozcan/Library/Python/2.7/lib/python/site-packages/flask/app.py", line 1344, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/ozcan/Documents/python/app.py", line 209, in login
    return render_template( themesDir + g.blogOptions['active_theme']+'/login.html', blogOptions = g.blogOptions, ref=ref )
  File "/Users/ozcan/Library/Python/2.7/lib/python/site-packages/flask/templating.py", line 124, in render_template
    return _render(ctx.app.jinja_env.get_or_select_template(template_name_or_list),
  File "/Users/ozcan/Library/Python/2.7/lib/python/site-packages/jinja2/environment.py", line 758, in get_or_select_template
    return self.get_template(template_name_or_list, parent, globals)
  File "/Users/ozcan/Library/Python/2.7/lib/python/site-packages/jinja2/environment.py", line 719, in get_template
    return self._load_template(name, self.make_globals(globals))
  File "/Users/ozcan/Library/Python/2.7/lib/python/site-packages/jinja2/environment.py", line 693, in _load_template
    template = self.loader.load(self, name, globals)
  File "/Users/ozcan/Library/Python/2.7/lib/python/site-packages/jinja2/loaders.py", line 115, in load
    source, filename, uptodate = self.get_source(environment, name)
  File "/Users/ozcan/Library/Python/2.7/lib/python/site-packages/flask/templating.py", line 61, in get_source
    raise TemplateNotFound(template)
TemplateNotFound: static/themes/default/login.html

Estou absolutamente certo de que o login.html está lá (static/themes/default/404.html) Por que isso pode ocorrer?

29
saidozcan

Você colocou seu modelo no lugar errado. Dos documentos Flask:

O Flask procurará modelos na pasta de modelos. Portanto, se seu aplicativo for um módulo, essa pasta estará próxima a ele, se estiver dentro de seu pacote: consulte os documentos para obter mais informações: http://flask.pocoo.org/docs/quickstart/# rendering-templates

51
Majid Zandi

Eu acho que você não deve acrescentar themesDir. Você só passa o nome do arquivo do modelo para o balão, e ele será procurado em uma pasta chamada templates relativa ao seu python.

4
Markus Unterwaditzer