mapping urls to subdirectories

0 views
Skip to first unread message

jemminger

unread,
Mar 6, 2006, 11:41:10 PM3/6/06
to TurboGears
in order to map a url like "site.com/foo", i've seen a post where Kevin
says:
[quote]
In your controllers.py file, you'd then make your Root class look
something like this:

class Root:
entries = Entries()
[/quote]

but i can't for the life of me get this to work. caveat: i'm a python
newbie.

i've tried placing a file named foo.py alongside controllers.py and
importing it via
from foo import Foo

class Root:
foo = Foo()

but all i get is an error
ImportError: No module named foo

can anyone offer some pointers?
thanks,
jeff

jemminger

unread,
Mar 7, 2006, 12:06:10 AM3/7/06
to TurboGears
i'm going to get the record for replying to myself...

after further investigation i found that my Foo class was being
resolved, but the template was not.

i'm using a template for foo.py in
templates/
foo/
foo.kid

still further experimentation suggests that each subdirectory of my
"templates" directory needs its own master.kid - is this correct? i
can't seem to get it to use the master in "templates"

Patrick Lewis

unread,
Mar 7, 2006, 9:31:15 AM3/7/06
to TurboGears
jemminger wrote:
> i'm using a template for foo.py in
> templates/
> foo/
> foo.kid
>
> still further experimentation suggests that each subdirectory of my
> "templates" directory needs its own master.kid - is this correct? i
> can't seem to get it to use the master in "templates"

You don't need a master template in each directory, assuming you want
to really only have one master. But, you do need to import the master
with something like

<?python
from myproject.templates import master
?>
<html py:extends="master" ...

ajones

unread,
Mar 7, 2006, 12:02:24 PM3/7/06
to TurboGears
This is a mostly unrelated tip, but when you are testing something use
different names for everything. I generally do it by appending the
name. So in my module foo I would have a fooclass that I am using
footemplate.kid to expose, etc. It stops you from accidentally
confusing the software, not to mention yourself.

jemminger

unread,
Mar 7, 2006, 7:02:19 PM3/7/06
to TurboGears
> <?python
> from myproject.templates import master
> ?>
> <html py:extends="master" ...

brilliant - that's what i needed!

jemminger

unread,
Mar 7, 2006, 7:10:18 PM3/7/06
to TurboGears
well, now a new problem has arisen: for some reason, clicking the link
to my newly mapped subdirectory works, but then triggers a server
restart?!?!? the master.pyc is removed, and any page refresh fails
because of this.

am i better off just keeping everything in the templates root?

jemminger

unread,
Mar 7, 2006, 7:39:51 PM3/7/06
to TurboGears
i've noticed that this restarting behavior only happens in development
mode... which is good for production apps obviously, but will make
development nearly impossible if using subdirs in templates... will i
be missing anything important if i develop in production mode?

Reply all
Reply to author
Forward
0 new messages