Forums

Can't get a template to load

I am using flask, and python 2.7, configured for an outside domain.

I am trying to set up a basic log in page. When I put html in quotes to be returned, it works fine, but when I try to call the html template I get an "Internal Service Error" [The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.]

@app.route('/' , methods = ['GET','POST'])
def login():
    error = None
    if request.method == 'POST':
        if request.form['username'] != 'usernameText' or request.form['password'] != 'passwordText' :
            error = "Invalid Credentials. Please Try again."
        else:
            return redirect(url_for('my_form1'))
    return render_template('/home/ExperimentsWithCode/domain/Templates/login.html', error = error)

I have tried

return render_template('home/ExperimentsWithCode/domain/Templates/login.html', error = error)    
return render_template('domain/Templates/login.html', error = error)    
return render_template('/domain/Templates/login.html', error = error)    
return render_template('/Templates/login.html', error = error)    
return render_template('Templates/login.html', error = error)    
return render_template('login.html', error = error)

Nothing seems to be working.

What am I doing wrong in calling this template?

The best way to track this down is probably to switch on debug mode. It sounds like you're using Flask, so you can do that by putting app.debug = True just after app = Flask(__name__)

It has a bunch of stuff which appears to summarize to

jinja2.exceptions.TemplateNotFound: home/ExperimentsWithCode/domain/Templates/login.html

jinja2.exceptions.TemplateNotFound: domain/Templates/login.html

jinja2.exceptions.TemplateNotFound: Templates/login.html

On the error page that loads in the browser: Error code: Unhandled Exception

What does your error log say?

2014-12-03 15:11:18,280 :/usr/lib/python2.7/threading.py:1160: RuntimeWarning: tp_compare didn't return -1 or -2 for exception
2014-12-03 15:11:18,280 :  return _active[_get_ident()]
2014-12-03 15:11:18,281 :Traceback (most recent call last):
2014-12-03 15:11:18,281 :  File "/bin/user_wsgi_wrapper.py", line 130, in __call__
2014-12-03 15:11:18,281 :    self.error_log_file.logger.exception("Error running WSGI application")
2014-12-03 15:11:18,281 :  File "/usr/lib/python2.7/logging/__init__.py", line 1185, in exception
2014-12-03 15:11:18,281 :    self.error(msg, *args, **kwargs)
2014-12-03 15:11:18,281 :  File "/usr/lib/python2.7/logging/__init__.py", line 1178, in error
2014-12-03 15:11:18,282 :    self._log(ERROR, msg, args, **kwargs)
2014-12-03 15:11:18,282 :  File "/usr/lib/python2.7/logging/__init__.py", line 1270, in _log
2014-12-03 15:11:18,282 :    record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra)
2014-12-03 15:11:18,282 :  File "/usr/lib/python2.7/logging/__init__.py", line 1244, in makeRecord
2014-12-03 15:11:18,283 :    rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func)
2014-12-03 15:11:18,283 :  File "/usr/lib/python2.7/logging/__init__.py", line 284, in __init__
2014-12-03 15:11:18,283 :    self.threadName = threading.current_thread().name
2014-12-03 15:11:18,283 :  File "/usr/lib/python2.7/threading.py", line 1160, in currentThread
2014-12-03 15:11:18,283 :    return _active[_get_ident()]
2014-12-03 15:11:18,284 :  File "/bin/user_wsgi_wrapper.py", line 122, in __call__
2014-12-03 15:11:18,284 :    app_iterator = self.app(environ, start_response)
2014-12-03 15:11:18,284 :  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1701, in __call__
2014-12-03 15:11:18,288 :    return self.wsgi_app(environ, start_response)
2014-12-03 15:11:18,288 :  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1689, in wsgi_app
2014-12-03 15:11:18,288 :    response = self.make_response(self.handle_exception(e))
2014-12-03 15:11:18,288 :  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1687, in wsgi_app
2014-12-03 15:11:18,289 :    response = self.full_dispatch_request()
2014-12-03 15:11:18,289 :  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1360, in full_dispatch_request
2014-12-03 15:11:18,289 :    rv = self.handle_user_exception(e)
2014-12-03 15:11:18,290 :  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1358, in full_dispatch_request
2014-12-03 15:11:18,290 :    rv = self.dispatch_request()
2014-12-03 15:11:18,290 :  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1344, in dispatch_request
2014-12-03 15:11:18,290 :    return self.view_functions[rule.endpoint](**req.view_args)
2014-12-03 15:11:18,291 :  File "/home/ExperimentsWithCode/meirgalimidi/flask_app.py", line 28, in login
2014-12-03 15:11:18,291 :    return render_template('home/ExperimentsWithCode/meirgalimidi/Templates/login.html')
2014-12-03 15:11:18,292 :  File "/usr/local/lib/python2.7/dist-packages/flask/templating.py", line 124, in render_template
2014-12-03 15:11:18,292 :    return _render(ctx.app.jinja_env.get_or_select_template(template_name_or_list),
2014-12-03 15:11:18,292 :  File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 830, in get_or_select_template
2014-12-03 15:11:18,293 :    return self.get_template(template_name_or_list, parent, globals)
2014-12-03 15:11:18,293 :  File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 791, in get_template
2014-12-03 15:11:18,293 :    return self._load_template(name, self.make_globals(globals))
2014-12-03 15:11:18,294 :  File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 765, in _load_template
2014-12-03 15:11:18,294 :    template = self.loader.load(self, name, globals)
2014-12-03 15:11:18,294 :  File "/usr/local/lib/python2.7/dist-packages/jinja2/loaders.py", line 113, in load
2014-12-03 15:11:18,294 :    source, filename, uptodate = self.get_source(environment, name)
2014-12-03 15:11:18,295 :  File "/usr/local/lib/python2.7/dist-packages/flask/templating.py", line 61, in get_source
2014-12-03 15:11:18,295 :    raise TemplateNotFound(template)
2014-12-03 15:11:18,295 :jinja2.exceptions.TemplateNotFound: home/ExperimentsWithCode/domain/Templates/login.html
2014-12-03 15:11:20,649 :Traceback (most recent call last):
2014-12-03 15:11:20,650 :  File "/bin/user_wsgi_wrapper.py", line 130, in __call__
2014-12-03 15:11:20,650 :    self.error_log_file.logger.exception("Error running WSGI application")
2014-12-03 15:11:20,650 :  File "/usr/lib/python2.7/logging/__init__.py", line 1185, in exception
2014-12-03 15:11:20,650 :    self.error(msg, *args, **kwargs)
2014-12-03 15:11:20,650 :  File "/usr/lib/python2.7/logging/__init__.py", line 1178, in error
2014-12-03 15:11:20,650 :    self._log(ERROR, msg, args, **kwargs)
2014-12-03 15:11:20,650 :  File "/usr/lib/python2.7/logging/__init__.py", line 1270, in _log
2014-12-03 15:11:20,651 :    record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra)
2014-12-03 15:11:20,651 :  File "/usr/lib/python2.7/logging/__init__.py", line 1244, in makeRecord
2014-12-03 15:11:20,651 :    rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func)
2014-12-03 15:11:20,651 :  File "/usr/lib/python2.7/logging/__init__.py", line 284, in __init__
2014-12-03 15:11:20,651 :    self.threadName = threading.current_thread().name
2014-12-03 15:11:20,651 :  File "/usr/lib/python2.7/threading.py", line 1160, in currentThread
2014-12-03 15:11:20,651 :    return _active[_get_ident()]
2014-12-03 15:11:20,652 :  File "/bin/user_wsgi_wrapper.py", line 122, in __call__
2014-12-03 15:11:20,652 :    app_iterator = self.app(environ, start_response)
2014-12-03 15:11:20,652 :  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1701, in __call__
2014-12-03 15:11:20,652 :    return self.wsgi_app(environ, start_response)
2014-12-03 15:11:20,652 :  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1689, in wsgi_app
2014-12-03 15:11:20,652 :    response = self.make_response(self.handle_exception(e))
2014-12-03 15:11:20,653 :  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1687, in wsgi_app
2014-12-03 15:11:20,653 :    response = self.full_dispatch_request()
2014-12-03 15:11:20,653 :  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1360, in full_dispatch_request
2014-12-03 15:11:20,653 :    rv = self.handle_user_exception(e)
2014-12-03 15:11:20,653 :  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1358, in full_dispatch_request
2014-12-03 15:11:20,654 :    rv = self.dispatch_request()
2014-12-03 15:11:20,654 :  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1344, in dispatch_request
2014-12-03 15:11:20,654 :    return self.view_functions[rule.endpoint](**req.view_args)
2014-12-03 15:11:20,654 :  File "/home/ExperimentsWithCode/domain/flask_app.py", line 28, in login
2014-12-03 15:11:20,655 :    return render_template('home/ExperimentsWithCode/domain/Templates/login.html')
2014-12-03 15:11:20,655 :  File "/usr/local/lib/python2.7/dist-packages/flask/templating.py", line 124, in render_template
2014-12-03 15:11:20,655 :    return _render(ctx.app.jinja_env.get_or_select_template(template_name_or_list),
2014-12-03 15:11:20,655 :  File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 830, in get_or_select_template
2014-12-03 15:11:20,655 :    return self.get_template(template_name_or_list, parent, globals)
2014-12-03 15:11:20,655 :  File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 791, in get_template
2014-12-03 15:11:20,655 :    return self._load_template(name, self.make_globals(globals))
2014-12-03 15:11:20,655 :  File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 765, in _load_template
2014-12-03 15:11:20,656 :    template = self.loader.load(self, name, globals)
2014-12-03 15:11:20,656 :  File "/usr/local/lib/python2.7/dist-packages/jinja2/loaders.py", line 113, in load
2014-12-03 15:11:20,656 :    source, filename, uptodate = self.get_source(environment, name)
2014-12-03 15:11:20,656 :  File "/usr/local/lib/python2.7/dist-packages/flask/templating.py", line 61, in get_source
2014-12-03 15:11:20,656 :    raise TemplateNotFound(template)
2014-12-03 15:11:20,656 :jinja2.exceptions.TemplateNotFound: home/ExperimentsWithCode/domain/Templates/login.html
2014-12-03 15:11:22,065 :Traceback (most recent call last):
2014-12-03 15:11:22,065 :  File "/bin/user_wsgi_wrapper.py", line 130, in __call__
2014-12-03 15:11:22,066 :    self.error_log_file.logger.exception("Error running WSGI application")
2014-12-03 15:11:22,066 :  File "/usr/lib/python2.7/logging/__init__.py", line 1185, in exception
2014-12-03 15:11:22,066 :    self.error(msg, *args, **kwargs)
2014-12-03 15:11:22,066 :  File "/usr/lib/python2.7/logging/__init__.py", line 1178, in error
2014-12-03 15:11:22,066 :    self._log(ERROR, msg, args, **kwargs)
2014-12-03 15:11:22,066 :  File "/usr/lib/python2.7/logging/__init__.py", line 1270, in _log
2014-12-03 15:11:22,067 :    record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra)
2014-12-03 15:11:22,067 :  File "/usr/lib/python2.7/logging/__init__.py", line 1244, in makeRecord
2014-12-03 15:11:22,067 :    rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func)
2014-12-03 15:11:22,067 :  File "/usr/lib/python2.7/logging/__init__.py", line 284, in __init__
2014-12-03 15:11:22,067 :    self.threadName = threading.current_thread().name
2014-12-03 15:11:22,067 :  File "/usr/lib/python2.7/threading.py", line 1160, in currentThread
2014-12-03 15:11:22,067 :    return _active[_get_ident()]
2014-12-03 15:11:22,067 :  File "/bin/user_wsgi_wrapper.py", line 122, in __call__
2014-12-03 15:11:22,068 :    app_iterator = self.app(environ, start_response)
2014-12-03 15:11:22,068 :  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1701, in __call__
2014-12-03 15:11:22,068 :    return self.wsgi_app(environ, start_response)
2014-12-03 15:11:22,068 :  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1689, in wsgi_app
2014-12-03 15:11:22,068 :    response = self.make_response(self.handle_exception(e))
2014-12-03 15:11:22,068 :  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1687, in wsgi_app
2014-12-03 15:11:22,069 :    response = self.full_dispatch_request()
2014-12-03 15:11:22,069 :  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1360, in full_dispatch_request
2014-12-03 15:11:22,069 :    rv = self.handle_user_exception(e)
2014-12-03 15:11:22,069 :  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1358, in full_dispatch_request
2014-12-03 15:11:22,070 :    rv = self.dispatch_request()
2014-12-03 15:11:22,070 :  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1344, in dispatch_request
2014-12-03 15:11:22,070 :    return self.view_functions[rule.endpoint](**req.view_args)
2014-12-03 15:11:22,070 :  File "/home/ExperimentsWithCode/domain/flask_app.py", line 28, in login
2014-12-03 15:11:22,071 :    return render_template('home/ExperimentsWithCode/domain/Templates/login.html')
2014-12-03 15:11:22,071 :  File "/usr/local/lib/python2.7/dist-packages/flask/templating.py", line 124, in render_template
2014-12-03 15:11:22,071 :    return _render(ctx.app.jinja_env.get_or_select_template(template_name_or_list),
2014-12-03 15:11:22,071 :  File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 830, in get_or_select_template
2014-12-03 15:11:22,071 :    return self.get_template(template_name_or_list, parent, globals)
2014-12-03 15:11:22,072 :  File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 791, in get_template
2014-12-03 15:11:22,072 :    return self._load_template(name, self.make_globals(globals))
2014-12-03 15:11:22,072 :  File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 765, in _load_template
2014-12-03 15:11:22,072 :    template = self.loader.load(self, name, globals)
2014-12-03 15:11:22,072 :  File "/usr/local/lib/python2.7/dist-packages/jinja2/loaders.py", line 113, in load
2014-12-03 15:11:22,072 :    source, filename, uptodate = self.get_source(environment, name)
2014-12-03 15:11:22,073 :  File "/usr/local/lib/python2.7/dist-packages/flask/templating.py", line 61, in get_source
2014-12-03 15:11:22,073 :    raise TemplateNotFound(template)
2014-12-03 15:11:22,073 :jinja2.exceptions.TemplateNotFound: home/ExperimentsWithCode/domain/Templates/login.html

Hi ExperimentsWithCode,

Where are you storing your templates in relation to your webapp? That will probably help us figure out what the correct template location is.

Alternatively if you don't mind if we take a look at your code on our end, we might be able to tell you what you did wrong there. (I can see it from my side, but we always ask permission.)

Yea. If you want to look around in the code, that would be greatly appreciated.

My flask_app.py is located in the directory beginning with an "m" and ending with an "i".

My template is nested within that directory in a directory called "Templates" and is the only file there. It is called "login.html".

Thank you for your assistance.

Hi there, just picking up on this while Conrad's away. With flask, I think you have to put your templates into a folder named "templates":

http://flask.pocoo.org/docs/0.10/tutorial/folders/

THANK YOU!!! That did the trick.

Successful path:

return render_template('login.html', error = error, url = str(url_for('my_form1')) )

So just the template file name, and no other path information, so long as the template is nested in a folder called "templates" all lower case.

Excellent, thanks for confirming!

Massive Thanks to Harry and Deleted-User, So just the template file name, and no other path information, so long as the template is nested in a folder called "templates" all lower case.

The lower case was the trick.

@Harry, I assume that you are a PA Developer/Support colleague. I would suggest you to update the capitalization thinggy on your portal as this is a case-sensitivity problem that we would not encounter on the local development environment, but its there on the the PA website

It's actually something that you would see on any computer apart from a Windows one -- Windows is unusual in regarding "Templates" and "templates" as being the same thing.

It is something we could perhaps put on our help pages somewhere -- where do you think it could go, where you would have seen it?