Template folder?

12 views
Skip to first unread message

Andrew Burton

unread,
Apr 11, 2008, 8:52:12 PM4/11/08
to Google App Engine
Is it possible to put my template files in a sub directory? I put a
path in app.yaml, moved my files into its corresponding directory,
added the path to the line where the templates get loaded, and when I
tested it out locally it seemed to work. However, once I uploaded it,
it seems to break.

marakas

unread,
Apr 12, 2008, 3:37:47 AM4/12/08
to Google App Engine
I am having the exact same problem so I have had to temporarily remove
the sub-directory.

Josh Flanagan

unread,
Apr 12, 2008, 10:01:55 AM4/12/08
to google-a...@googlegroups.com
Are you referring to the Django-style templates? You do not need an
entry in app.yaml for those, as they are not accessed directly by
outsiders.

Assuming a "templates" subfolder, you can then reference the template
as 'templates/mytemplate.html'

This works for me locally (I do not have an invite to production so
cannot test). I know you got it working locally too, I just wonder if
whatever you put in app.yaml is causing problems.

Andrew Burton

unread,
Apr 12, 2008, 2:00:55 PM4/12/08
to Google App Engine
> This works for me locally (I do not have an invite to production so
> cannot test). I know you got it working locally too, I just wonder if
> whatever you put in app.yaml is causing problems.

That worked! It shouldn't, because the app.yaml file just sets up
handlers, pour syrup on me and call me flapjacks it worked. Thanks!

Harlley

unread,
Jun 2, 2008, 4:34:38 PM6/2/08
to Google App Engine
Hi,

How did you solve this problem?

kscott

unread,
Jun 2, 2008, 7:47:50 PM6/2/08
to Google App Engine
I created a folder I called html and put all of my templates in that
directory.

Then use the following code:

path = os.path.join(os.path.dirname(__file__), 'html/
home.htm')
self.response.out.write(template.render(path,
template_values) )

Harlley Roberto

unread,
Jun 2, 2008, 8:53:44 PM6/2/08
to google-a...@googlegroups.com
I did in that way too, but it's just works locally
--
=================
Harlley R. Oliveira
www.webtoo.com.br
=================

bowman...@gmail.com

unread,
Jun 2, 2008, 10:11:49 PM6/2/08
to Google App Engine
I do it as simply as

def get(self):
template_values = { }
path = os.path.join(os.path.dirname(__file__), 'templates/
index.html')
self.response.out.write(template.render(path, template_values))

My templates are stored in a directory call templates under the root
of the main file

main.py
templates/index.html

Feel free to grab the appengine-utilities demo to see this working.
http://code.google.com/p/appengine-utitlies/downloads/list

That is what's running on http://gaeutilities.appspot.com so you can
see it working both locally and hosted.
> =================- Hide quoted text -
>
> - Show quoted text -

Harlley Roberto

unread,
Jun 3, 2008, 8:41:00 AM6/3/08
to google-a...@googlegroups.com
It works! Thanks a lot

Kambiz Kambiz

unread,
Jun 8, 2008, 2:28:02 AM6/8/08
to Google App Engine
I current have the exact same setup as you, i.e. my templates are in a
templates folder and the path to the templates are laid out just like
the snippet you provided but it didn't work for me.

path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, template_values))

Do you have a handler in your app.yaml file? Like:

- url: /templates
static_dir: templates

On Jun 2, 7:11 pm, "bowman.jos...@gmail.com" <bowman.jos...@gmail.com>
wrote:
> I do it as simply as
>
> def get(self):
> template_values = { }
> path = os.path.join(os.path.dirname(__file__), 'templates/
> index.html')
> self.response.out.write(template.render(path, template_values))
>
> My templates are stored in a directory call templates under the root
> of the main file
>
> main.py
> templates/index.html
>
> Feel free to grab the appengine-utilities demo to see this working.http://code.google.com/p/appengine-utitlies/downloads/list
>
> That is what's running onhttp://gaeutilities.appspot.comso you can

bowman...@gmail.com

unread,
Jun 8, 2008, 10:50:45 AM6/8/08
to Google App Engine
path = os.path.join(os.path.dirname(__file__), 'templates/
index.html')

note, the templates/

On Jun 8, 2:28 am, Kambiz Kambiz <kam...@gmail.com> wrote:
> I current have the exact same setup as you, i.e. my templates are in a
> templates folder and the path to the templates are laid out just like
> the snippet you provided but it didn't work for me.
>
>     path = os.path.join(os.path.dirname(__file__), 'index.html')
>     self.response.out.write(template.render(path, template_values))
>
> Do you have a handler in your app.yaml file? Like:
>
> - url: /templates
>   static_dir: templates
>
> On Jun 2, 7:11 pm, "bowman.jos...@gmail.com" <bowman.jos...@gmail.com>
> wrote:
>
>
>
> > I do it as simply as
>
> > def get(self):
> >     template_values = {    }
> >     path = os.path.join(os.path.dirname(__file__), 'templates/
> > index.html')
> >     self.response.out.write(template.render(path, template_values))
>
> > My templates are stored in a directory call templates under the root
> > of the main file
>
> > main.py
> > templates/index.html
>
> > Feel free to grab the appengine-utilities demo to see this working.http://code.google.com/p/appengine-utitlies/downloads/list
>
> > That is what's running onhttp://gaeutilities.appspot.comsoyou can

Kambiz Kambiz

unread,
Jun 8, 2008, 11:29:46 AM6/8/08
to Google App Engine
I made sure I have templates/ this time:

path = os.path.join(os.path.dirname(__file__), 'templates/
index.html')
self.response.out.write(template.render(path, template_values))

And I get:

Traceback (most recent call last):
File "/base/python_lib/versions/1/google/appengine/ext/webapp/
__init__.py", line 499, in __call__
handler.get(*groups)
File "/base/data/home/apps/kambizkamrani/1.25/main.py", line 44, in
get
self.response.out.write(template.render(path, template_values))
File "/base/python_lib/versions/1/google/appengine/ext/webapp/
template.py", line 80, in render
t = load(template_path, debug)
File "/base/python_lib/versions/1/google/appengine/ext/webapp/
template.py", line 108, in load
template = django.template.loader.get_template(file_name)
File "/base/python_lib/versions/1/django/template/loader.py", line
79, in get_template
source, origin = find_template_source(template_name)
File "/base/python_lib/versions/1/django/template/loader.py", line
72, in find_template_source
raise TemplateDoesNotExist, name
TemplateDoesNotExist: index.html

Kambiz

On Jun 8, 7:50 am, "bowman.jos...@gmail.com" <bowman.jos...@gmail.com>
wrote:

bowman...@gmail.com

unread,
Jun 8, 2008, 10:36:23 PM6/8/08
to Google App Engine
It's still not seeing your template. Make sure the file is
"index.html" and that it has proper permissions.

Harlley Roberto

unread,
Jun 9, 2008, 8:51:11 AM6/9/08
to google-a...@googlegroups.com
I did so

path = os.path.join(os.getcwd(), 'templates/index.html')

and works perfectly



=================
Harlley R. Oliveira
www.webtoo.com.br
=================

Reply all
Reply to author
Forward
0 new messages