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!
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.