Hi Xie -

The reason this worked as you described:

For each request to your application,  web2py runs, finds your (the request)
application,
executes each file in the models directory (since the connection needs to be
defined),
and then calls the controller file and function in controllers.

When you put a file in modules, you need to be sure it is imported, and the
definitions available to your controllers.

To do this you need to:


   - put an empty (at least)  __init__.py    file in your application's
   modules  folder (this marks it as a module)
   - somewhere that you know get's executed, e.g. in your models folder,
   put an import statement.

For example, in applications/my_app/models/0.py,  add a line like this:

from applications.my_app.modules.utils import App

Hope this helps.

Regards,
Yarko



On Tue, Jun 30, 2009 at 11:41 PM, Iceberg <[email protected]> wrote:

>
> On Jul1, 12:08pm, Xie <[email protected]> wrote:
> > Recently I'm having some trouble with web2py but I don't know where
> > the problem is. My best guess is that it's about the MVC namespace.
> > Please correct me if I'm wrong.
> >
> > The problem is that I defined a class "App" in models/utils.py and
> > when I tried to inherit this class in another .py file under the
> > models directory, web2py told me that class "App" is not found. I was
> > confused and moved class "App" to db.py(where database connection is
> > defined) and *bang*, it worked. No more error ticket and class "App"
> > is successfully inherited.
> >
> > I'm not that familiar with web2py internals. Why did this happen? Is
> > there any resolution order or something?
> >
> > Thanks
> >
> > -- Xie
>
>
> web2py loads models in alphabetic order. So you need to make sure your
> basic definition comes prior to your "another .py file".  For example,
> "models/0_setting.py" is kind of de facto convention.
>
> However, I would recommend you to put your basic things inside modules/
> whatever.py, this way you might have more flexibility.
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to