Zaffiro
Zaffiro

Reputation: 4934

TemplateNotFound When Deployed to Google App Engine Site

Updated: Feb, 22 Per Lipis's request. I added the code to render the template.

I developed an admin section on my website which worked fine in my local environment (localhost:8080). When I deployed the application to my appengine site I get the TemplateNotFound error when I navigate to http: //myapp/myadmin/ which should pick up the default.html file in the admin directory. The html file lives under the templates\admin directory.

The file structure for my templates are:

--app
  --templates
    --admin
          -default.html 
    -file.html
    -file1.html
    -file2.html

I am using the following code to create the Jinja environment:

FolderPath = os.path.dirname(os.path.dirname(__file__))
jinja_environment = jinja2.Environment(
    loader=jinja2.FileSystemLoader(
        [
            os.path.join(FolderPath,"templates\\admin"),
            os.path.join(FolderPath,"templates")
        ]
    )
)

Updated -- Template Render Code:

template_values = {}

template = jinja_environment.get_template('default.html')
self.response.out.write(template.render(template_values))

I am assuming its the "FolderPath" variable that is causing the problem but not 100% sure. Has anyone run into this problem?

ERROR:

default.html Traceback (most recent call last): File "/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1511, in call rv = self.handle_exception(request, response, e) File "/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1505, in call rv = self.router.dispatch(request, response) File "/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher return route.handler_adapter(request, response) File "/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1077, in call return handler.dispatch() File "/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 547, in dispatch return self.handle_exception(e, self.app.debug) File "/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 545, in dispatch return method(*args, **kwargs) File "/base/data/home/apps/s~myapp/0-2-5.365473085936457098/app/controllers/admin.py", line 42, in get template = jinja_environment.get_template('default.html') File "/python27_runtime/python27_lib/versions/third_party/jinja2-2.6/jinja2/environment.py", line 719, in get_template return self._load_template(name, self.make_globals(globals)) File "/python27_runtime/python27_lib/versions/third_party/jinja2-2.6/jinja2/environment.py", line 693, in _load_template template = self.loader.load(self, name, globals) File "/python27_runtime/python27_lib/versions/third_party/jinja2-2.6/jinja2/loaders.py", line 115, in load source, filename, uptodate = self.get_source(environment, name) File "/python27_runtime/python27_lib/versions/third_party/jinja2-2.6/jinja2/loaders.py", line 180, in get_source raise TemplateNotFound(template) TemplateNotFound: default.html

Thanks in advance for your help!

Upvotes: 0

Views: 657

Answers (2)

user784435
user784435

Reputation:

Ideally use Linux (Possibly Ubuntu or Mint) It will save you headaches in the long run as well

Upvotes: 0

Dave W. Smith
Dave W. Smith

Reputation: 24966

Try "templates/admin". That backslash thing is a Windows-ism.

Upvotes: 1

Related Questions