Total noob Q: how to specify subdirectories in app.yaml?

2,106 views
Skip to first unread message

King Skippus

unread,
Jul 9, 2008, 7:17:35 PM7/9/08
to Google App Engine
This is my very first day ever looking at App Engine. Oh, and
Python. And YAML. That being said, I'm running into a really stupid
problem that I just can't seem to get around.

I have some templates stored in an application directory called source/
templates. I'd like to be able to access them, so in my app.yaml
file, I put the following:

handlers:
- url: /css
static_dir: source/templates

- url: /.*
script: source/Main.py

When I try to pull up a file in that directory, though, I'm getting
the following error from my dev_appserver.py console:

Error encountered reading file "E:\Docs\Projects\myapp\source
emplates"

That spacing after the word source is a tab. Apparently, the source/
templates is being interpreted as source(tab)emplates. I've tried
various ways of escaping the /t, but to no avail. I'm running all of
this on Windows Vista x64.

How the heck do you create a static subdirectory that has a component
that starts with a t?

Grrr...
TonyV

TLH

unread,
Jul 10, 2008, 10:34:48 AM7/10/08
to Google App Engine
Have you tried the Python "raw string" syntax? In your .py file,
where you have ...

"E:\Docs\Projects\myapp\source\templates"

... change it to ...

r"E:\Docs\Projects\myapp\source\templates"

Sylvain

unread,
Jul 10, 2008, 11:19:03 AM7/10/08
to Google App Engine
handlers:
- url: /css
static_dir: source/templates

- url: /.*
script: source/Main.py

Did you try to put Main.py at the root ?
- url: /.*
script: /Main.py

because "source" is in the static_dir too. There is maybe an issue
with it.

donut

unread,
Jul 10, 2008, 2:59:17 AM7/10/08
to Google App Engine
I'm not completely sure, but if it's a string the typical solution
would be to escape the slash like so:

"E:\Docs\Projects\myapp\source\\templates"

But I'm mostly a PHP guy and that's how it would work in PHP, though
I'm really sure it should work the same way in Python. Let me know how
it goes.

Wooble

unread,
Jul 10, 2008, 3:49:48 PM7/10/08
to Google App Engine


On Jul 10, 10:34 am, TLH <tlhola...@gmail.com> wrote:
> Have you tried the Python "raw string" syntax? In your .py file,
> where you have ...
>
> "E:\Docs\Projects\myapp\source\templates"
>
> ... change it to ...
>
> r"E:\Docs\Projects\myapp\source\templates"

I think the problem is that he has nothing of the sort in any .py
file; it's in app.yaml.

It sounds like a bug in the Windows version; the /'s are being
converted to \'s without escaping them.

TLH

unread,
Jul 11, 2008, 1:33:15 PM7/11/08
to Google App Engine
This:

On Jul 10, 3:49 pm, Wooble <geoffsp...@gmail.com> wrote:
> It sounds like a bug in the Windows version; the /'s are being
> converted to \'s without escaping them.

I was able to reproduce his problem using the Windows version of
dev_appserver.py.

I suspect this section, starting at line 2393 in tools/
dev_appserver.py

regex = url_map.url
path = url_map.GetHandler()
if handler_type == appinfo.STATIC_DIR:
if regex[-1] == r'/':
regex = regex[:-1]
if path[-1] == os.path.sep:
path = path[:-1]
regex = '/'.join((re.escape(regex), '(.*)'))
if os.path.sep == '\\':
backref = r'\\1'
else:
backref = r'\1'
path = os.path.normpath(path) + os.path.sep + backref

url_matcher.AddURL(regex,
dispatcher,
path,
requires_login, admin_only)

TLH

unread,
Jul 11, 2008, 2:48:25 PM7/11/08
to Google App Engine
TonyV,

I was able to reproduce your problem in a Windows environment. The
bug appears to be in the way the STATIC_DIR handler converts slashes
to backslashes. There is no such bug in the STATIC_FILES handler, so
there is a workaround:

Instead of ...

- url: /css
static_dir: source/templates

... use ...

- url:/css/(.*)
static_files: source/templates/\1
upload: source/templates/(.*)




On Jul 9, 7:17 pm, TonyV <kingskip...@gmail.com> wrote:
Reply all
Reply to author
Forward
Message has been deleted
0 new messages