2

I have an application with the following files

/path_to_app
   app.py
   /html
      page.html
   /js
      page.js

In app.py I load and render a mako template. The template file is page.html in the html directory. That page contains contains a line:

     <%include file="../js/page.js" />

which is intended to find and include the appropriate page of javascript (after performing mako substitutions on that file). This works fine on my Windows development machine but when I deploy to a Ubuntu linux server for further testing it throws the error: TemplateLookupException: Template uri "../js/fund_page.js" is invalid - it cannot be relative outside of the root path.

changing the include to make it absolute to the application root:

     <%include file="/js/page.js" />

doesn't help, that returns the message: TemplateLookupException: Cant locate template for uri u'/js/fund_page.js'.

What change is necessary to be able to use this mako include on Linux, and is it possible to express it in a fashion that will be compatible with both Windows and Linux?

Larry Lustig
  • 49,320
  • 14
  • 110
  • 160

2 Answers2

0

I solved this problem using the simple expedient of moving the included js file into the same directory as the html file that calls it.

Larry Lustig
  • 49,320
  • 14
  • 110
  • 160
-1

You should add the parent directory of "js" to the directories parameter of your TemplateLookup instance. For example:

mako_lookup = TemplateLookup(directories=[ root + "/project/templates",
                                           root + "/public"])
Joril
  • 19,961
  • 13
  • 71
  • 88