On Apr 20, 2004, at 3:28 PM, jsibre@sibre.org wrote: > The Quixotic idiom is that namespaces become the 'directories' of your > URLs, and > methods/functions become the 'files' of your URLs. Hence, namespaces > (of an > instance of a class, module, package, etc) should have trailing > slashes, > because they don't really do anything 'webbish' on their own. Given > the url > "/ui/" (for example), quixote will implicitly serve it as if you'd > requested > "/ui/_q_index". That's why it wants to convert "/ui" (again, for > example) to > "/ui/", and breaks if you don't allow it to do so (i.e., you set > FIX_TRAILING_SLASHES to 0). Okay, I understand this. I notice that if I put the trailing slash into the hrefs that need them, there one less step for quixote to do. That's enough reason to do so, and can override my stylistic preference... > A notable exception to this is when a namespace is > callable (i.e., have a __call__() defined). In those cases, quixote > won't look > for the _q_index. Going back to the example, "/ui" would work, and it > would be > as if you'd requested "/ui/__call__"... > [You'll actually see similar options / behavior apache, if you ever > look for > them. Of course, the names are different.] Thanks for this; I may need it sometime. >> [...] >> >> However, I'm still baffled by the mechanics of importing and exporting >> files and methods *across directories*. Say, for example, I had a >> subdirectory inside the /qxdemo/ui directory - let's call it 'foo' and >> it has a 'bar.ptl' page with a method called 'run()'. How and where do >> I expose the 'run()' method? From /qxdemo/ui/__init__.py? From >> /qxdemo/ui/foo/__init__.py? From both? All the failed experiments I >> tried with qxdemo have left me wondering how to think 'quixotically' >> with respect to exposing methods and pages to the web across >> directories. > > Again with the head scratching. I hope I'm not just misunderstanding > you here, > and causing more confusion rather than reducing it, but I think this > question > stems from not yet 'getting' the quixote publishing method. Yes, that's what I'm trying to get. > Assume we have this structure: > .../qxdemo/ui/__init__.py > .../qxdemo/ui/foo/__init__.py > .../qxdemo/ui/foo/bar.ptl > > as long as: > the _q_exports of ui/__init__.py contains 'foo' in it, > and > the _q_exports of ui/foo/__init__.py contains 'bar' in it, > and > the _q_exports of ui/foo/bar.ptl contains 'run' in it, > you're done! If only it were so simple! Well, I tried exactly this, and it didn't work, and I cannot figure out why. From the top, this is what I have: 1. qxdemo.cgi ---> app = Publisher('qxdemo.ui') # only relevant lines shown 2. qxdemo/ui/__init__.py ---> _q_exports = ['foo'] from qxdemo.ui import foo 3. qxdemo/ui/foo/__init__.py ---> _q_exports = ['bar'] 4. qxdemo/ui/foo/bar.ptl ---> _q_exports = ['run'] def run [html] (request): "This is the run method." When I go to http://server/qxdemo/foo/bar/run I get the following error message in the browser window: '''Page not found: /qxdemo/foo/bar/run: None has no _q_exports list.''' I had earlier tried it without importing 'foo' in qxdemo/ui/__init__.py but that led to a different error message: '''ImportError: No module named foo''' which is why I added it to the import line. An alternative way of getting 'foo' into the namespace I tried was to add it as a StaticDirectory, but Graham showed how that was poor practice for interface files (and besides, it didn't work!) Any ideas what is missing? > A request to /foo/bar/run (assuming 'ui' is the app's root) will call > the run() > method. (I think... I've been doing my publishing with live classes > rather > than modules and packages lately, so I'm not positive about the > details on the > package importing the module... Someone wanna sanity-check me?) > > Of course, you COULD import the run() method up to a higher level with > something > like: > [in ui/__init__.py] > from foo.bar import run > _q_exports = ['run'] > > and then request "/run". This sounds like something to try after I get the basics running. > And there's nothing wrong with that. In fact, sometimes doing this is > helpful. > Just so long as you're aware of the alternatives, and not just pulling > everything up into your root namespace because you didn't know that > you didn't > have to. > > Hope this helps some. I do appreciate your help in trying to troubleshoot the issue. I know that the principles involved are (seemingly) simple, but for some reason I can't get the 'foo' subdirectory to be seen by quixote. If anyone has any ideas of what to try, I'll be glad to experiment. Thanks! John Miller