I am using Jinja2 templates for my GAE Python application. Actually there are a couple of small applications inside one project. They are, for example, blog and site. So, the first one is for blog and the second one is for site =). I have this folders structure:
/
/apps
/blog
/site
/templates
/blog
/site
I also have a code for accessing templates folder for each application. It looks like this:
template_dirs = []
template_dirs.append(os.path.join(os.path.dirname(__file__), 'templates/project'))
Of course, it doesn't work as it's wrong. It returns a string like this: base/data/home/apps/myapplication/1.348460209502075158/apps/project/templates/project
And I need it to return a string like this: base/data/home/apps/myapplication/1.348460209502075158/apps/templates/project How can I do that using absolute paths, not relative? I suppose I need to get the root of the my whole GAE project some way. Thanks!
Why not put an os.path.abspath around file
It's kind of a kludge, and I didn't write this with the love and caring I write most of my code with, but maybe this will be useful for you...
Please note that for this to work on the SDK your application's root directory MUST be named the same as your application's ID.
Additionally, this makes assumptions about the directory structure used by Google on the production servers, so it's entirely possible that they could change something and break this.
The easiest way to get the root path of your app is to put a module in the root of your app, which stores the result of
os.path.dirname(__file__)
, then import that where needed. Alternately, callos.path.dirname(module.__file__)
on a module that's in the root of your app.