pyramid_mako not finding templates. is there a hook to find the directory / file being called?

242 views Asked by At

This one is really really buggging me.

Will start by saying that everything is working perfectly on my local machine. On the server however, whatever I do ends up in a "Can not locate template for uri: ..."

On my local machine I use a Linux VM on Mac OS X. I have looked into case-sensitivity issues between file names. No dice.

I orignally had everything working by calling the files locally.

To confirm, I switched to using the mako.directories = app:templates config and moved my templates directory from inside my app.views package to a app:template folder—which is a new folder names in lowercase.

On this configuration wasn't working.

I decided to be more explict.

So I called my mako files by doing:

 @view_config(renderer='myapp:templates/template1.mak')
 def template1(self):
      pass

Still no dice.

Tried being explicit locally.

 @view_config(renderer='templates/template2.mak')
 def template2(self):
      pass

Still failing.

And of course, when using mako.directories in config, it still dosent work.

 @view_config(renderer='template3.mak')
 def template3(self):
      pass

Is there a way to hook into this to see the specific filepath being called? Something much larger than 'templates/template.mak'?

For reference these are what the URI int the Pyramid TopLevelException looks like respectivley:

Exception
=========
"Can not locate template for uri %r" % uri)
mako.exceptions.TopLevelLookupException: Can not locate template for uri
========

'app:templates/template1.mak    
'app.views:templates/template2.mak'
1

There are 1 answers

1
ovatsug25 On BEST ANSWER

I figured out why it's not working!

I run python setup.py install on my server before I load my Pyramid app. All the python source-code is moved to my site-packages folder in my VENV but (importantly) my MAKO files are not moved there.

When I run python setup.py develop, because my packages are installed as symlinks, my MAKO files still live in my project.

Thought the name would indicate otherwise, pyramid projects that use non python files (such as templates) can not be installed! They must be maintained in that develop state.

If we can run these with python setup.py develop, please indicate that to me in the comments! I may be missing something.

Edit 1:

This is going in the right direction but I'm not sure how to use it:

https://docs.python.org/2/distutils/setupscript.html#installing-package-data

(Edit 3): Including non-Python files with setup.py

Edit 2:

This cued me in Preparing a pyramid app for production