On Monday, October 21, 2013 12:57:31 AM UTC-4, 黄祥 wrote:
>
> yes, i redefined db variable in db_wizard_service.py when i put it on the
> sub folder service.
> please find attached file.
> 1. i started from scratch.
> 2. on attached file, it can work but the news and service link don't have
> menu (test in default and manage controller)
>
Currently, in db.py you have:
if 'news' in request.function:
response.models_to_run = ['db_wizard_news.py']
That means that after db.py, db_wizard_news.py will be the *only* model
file to run, so menu.py never gets run. Instead, it should be:
response.models_to_run = ['db_wizard_news.py', 'menu.py']
> 3. if i use the folder subfolder, move db_wizard_news.py to news subfolder
> and move db_wizard_service.py to service folder, it's not work even i've
> already define it on db.py
> if 'news' in request.function:
> response.models_to_run = ['news/']
> elif 'service' in request.function:
> response.models_to_run = ['service/']
> error :
> AttributeError: 'DAL' object has no attribute 'service'
>
In this case, because menu.py is in the root folder, it will get run before
the models in the subfolder. However, menu.py refers to the db.service
table, which is defined in a model file in the subfolder, so it doesn't yet
exist.
Also, if you take the subfolder approach, you should not duplicate all the
menu.py code in each subfolder. Instead, run the main menu code in the
menu.py in the root folder, and in the subfolders, just add some code to
manipulate the response.menu object. Alternatively, you can move the menu
code into a function that gets imported, which you can call from the
subfolder model file or the main db.py file, depending on the condition.
Anthony
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.