So, I did the trivial “workouts” using GAE. Now I would like to build something with a more complex directory structure. Sort of:
siteroot/ models/ controllers/ controller1/ controller2/ ... templates/ template1/ template2/ ...
.. etc. Controllers will handle Python module requests. Then they would need to find (Django-style) templates in related folders. Most of the demo applications I've seen allow template paths as follows:
path = os.path.join(os.path.dirname(__file__), 'myPage.html')
... the __ file __ property allows the currently executing script. So, in the above example, if a Python script was run in controllers / controller 1 /, then "myPage.html" allowed the same directory - controllers / controller 1 / myPage.html - and I would prefer to cleanly separate my code and templates into Python
The solution I hack feels ... hacky:
base_paths = os.path.split(os.path.dirname(__file__)) template_dir = os.path.join(base_paths[0], "templates")
So, I just discard the last element of the path for the current script run and add the template directory to the new path. The other (non-GAE) solutions I've seen to solve Python paths seem pretty heavyweight (like splitting paths into lists and managing them). Django seems to have an answer to this question, but I would rather stick with the GAE API, as well as create a complete Django application and modify it for GAE.
I assume that something hard-coded will not be a starter, since applications live on an endless farm of Google servers. So what's the best way?
source share