durusmail: quixote-users: Traversing objects without using _q_lookup
Traversing objects without using _q_lookup
2003-10-03
2003-10-03
Traversing objects without using _q_lookup
Neil Schemenauer
2003-10-03
On Fri, Oct 03, 2003 at 10:33:53AM -0400, Merrell, Brian L. wrote:
> Something like:
>
> import myClass from myClassPythonfile
> _q_exports= ["myClass"]
>
> myClass has a _q_index method but when I load the URL:
>
> http://localhost:8080/myClass/
>
> I get nothing on the screen and when I view the source, I see a reference to
> the object (ie something like ) It doesn't seem
> to be traversing it.

That's not what I get.  I see:

  TypeError: unbound method _q_index() must be called with Klass
  instance as first argument (got HTTPRequest instance instead)

Putting a class in _q_exports doesn't work because Quixote does not
instantiate it.  You could do something like this:

    from myClassPythonfile import myClass

    _q_exports= ["myPage"]

    def myPage(request):
        return myClass()

If you don't want to create one instance per request you could do
this:

    from myClassPythonfile import myClass

    _q_exports= ["myInstance"]

    myInstance = myClass()

HTH,

  Neil