Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #1915 (closed defect: fixed)

Opened 11 years ago

Last modified 11 years ago

Mako template path issue (TopLevelLookupException: Cant locate template for uri '/t2/templates/test.mak')

Reported by: cd34 Owned by: percious
Priority: normal Milestone: 2.0b1
Component: TurboGears Version: trunk
Severity: normal Keywords: mako
Cc:

Description (last modified by jorge.vargas) (diff)

When trying to use the mako templating engine, there is a path issue dealing with the template location.

While I am sure my solution is not the right one, I don't have the expertise to delve into the middleware to know what is being passed in order to properly pass or parse the directory path.

When one selects mako in a template and puts the template into the templates directory, the following error is raised:

TopLevelLookupException?: Cant locate template for uri '/t2/templates/test.mak'

From the backtrace, we're able to see the following:

dir  	'/var/www/tg2/t2/t2/templates'
self 	<mako.lookup.TemplateLookup object at 0x8c4cdcc>
srcfile 	'/var/www/tg2/t2/t2/templates/t2/templates/test.mak'
u 	't2/templates/test.mak'
uri 	'/t2/templates/test.mak'

and if we look closely at dir and u which are joined later:

srcfile = posixpath.normpath(posixpath.join(dir, u))

we can see that it will append dir + u and end up with

/var/www/tg2/t2/t2/templates/t2/templates/test.mak

which will raise an exception.

in the file, lib/python2.5/site-packages/Mako-0.2.0-py2.5.egg/mako/lookup.py

replacing line 66 which contains

            u = re.sub(r'^\/+', '', uri)

with

            u = re.sub(r'^\/+.*\/.*\/', '', uri)

fixes the problem, however, I'm reasonably sure it is not the correct solution.

Change History

comment:1 Changed 11 years ago by cd34

evidently the lines are parsed by the wiki. Just to make sure it is clear.

original line 66:
            u = re.sub(r'^\/+', '', uri)

'hacked' line 66 to make it work:
            u = re.sub(r'^\/+.*\/.*\/', '', uri)

comment:2 Changed 11 years ago by mramm

What version if TG us this happening in?

comment:3 Changed 11 years ago by cd34

TurboGears2-1.9.7a3dev_r5035-py2.5.egg

comment:4 Changed 11 years ago by Chris Arndt

  • Version changed from 1.1b1 to trunk
  • Milestone set to 1.9.7b1

comment:5 Changed 11 years ago by mramm

Hmm, it looks like the template path in config is not setup properly.

comment:6 Changed 11 years ago by mramm

  • Owner changed from anonymous to percious
  • Milestone changed from 1.9.7b1 to 2.0b1

comment:7 Changed 11 years ago by faide

Chris could you do a few things for me:

  • "svn up" and test again because I changed a lot of things regarding the template lookup system.
  • tell us if you're using legacy renderers or new style function renderers
  • Take care that when you update tg2 trunk you'll be using new style renderers by default
  • look into your app_cfg.py to make sure you have not overridden the base_config.use_legacy_renderer to True (it is False by default in the new head of trunk since a few hours).

comment:8 Changed 11 years ago by cd34

(1915)daviesinc@pch1:/var/www$ virtualenv --no-site-packages trac1915 New python executable in trac1915/bin/python Installing setuptools............done. (1915)daviesinc@pch1:/var/www$ cd trac1915/ (1915)daviesinc@pch1:/var/www/trac1915$ source bin/activate (trac1915)daviesinc@pch1:/var/www/trac1915$ easy_install -i  http://www.turbogears.org/2.0/downloads/1.9.7b2/index tg.devtools Searching for tg.devtools Reading  http://www.turbogears.org/2.0/downloads/1.9.7b2/index/tg.devtools/ Best match: tg.devtools 1.9.7b2 Downloading  http://www.turbogears.org/2.0/downloads/1.9.7b2/tg.devtools-1.9.7b2.tar.gz Processing tg.devtools-1.9.7b2.tar.gz

[clipped]

(trac1915)daviesinc@pch1:/var/www/trac1915$ paster quickstart Enter project name: trac1915 Enter package name  [trac1915]: Do you need authentication and authorization in this project? [yes] no Selected and implied templates:

tg.devtools#turbogears2 TurboGears 2.0 Standard Quickstart Template

Variables:

auth: False egg: trac1915 elixir: False package: trac1915 project: trac1915 sqlalchemy: True sqlobject: False tgversion: 1.9.7b2

Creating template turbogears2 Creating directory ./trac1915

[clipped]

(trac1915)daviesinc@pch1:/var/www/trac1915/trac1915$ paster serve --reload development.ini Starting subprocess with file monitor Starting server in PID 2520. serving on 0.0.0.0:8080 view at  http://127.0.0.1:8080

(trac1915)daviesinc@pch1:/var/www/trac1915/trac1915/trac1915/templates$ cat test.mak test

in controllers/root.py

@expose('mako:trac1915.templates.test') def test(self):

return dict()

From the debug info:

dir '/var/www/trac1915/trac1915/trac1915/templates' self <mako.lookup.TemplateLookup? object at 0x8f75d2c> srcfile '/var/www/trac1915/trac1915/trac1915/templates/trac1915/templates/test.mak' u 'trac1915/templates/test.mak' uri '/trac1915/templates/test.mak' view << return self.load(srcfile, uri)

else:

raise exceptions.TopLevelLookupException?("Cant locate template for uri '%s'" % uri)

def adjust_uri(self, uri, relativeto):

raise exceptions.TopLevelLookupException?("Cant locate template for uri '%s'" % uri)

TopLevelLookupException?: Cant locate template for uri '/trac1915/templates/test.mak'

The path for srcfile in this case should be:

/var/www/trac1915/trac1915/trac1915/templates

and in the debug you can see that it is:

srcfile '/var/www/trac1915/trac1915/trac1915/templates/trac1915/templates/test.mak'

As of the latest beta, unless I'm doing something wrong, the bug still exists.

comment:9 Changed 11 years ago by faide

Please! try to format the ticket a bit so we can read it :)

Could you try with the trunk version from the SVN ? I was asking if someone could try the latest changes I made in the SVN this morning related to #1942

Because reading your posted info I think it should work...

comment:10 Changed 11 years ago by jorge.vargas

  • Description modified (diff)

comment:11 Changed 11 years ago by faide

  • Status changed from new to closed
  • Resolution set to fixed

This was due to a problem with Mako inheritance that was not working with new style renderers and dotted names.

This has been fixed in trunk.

Please re-open if you still have a problem.

comment:12 Changed 11 years ago by faide

see r5911 for info

Note: See TracTickets for help on using tickets.