Anthony <abastardi@...> writes: > > > Hi James, > > It sounds like you might be thinking of how a PHP app might work, where your URL points to a particular .php file, and that file is then processed to generate the returned web page. web2py does not work that way. To get a better understanding of how web2py does it, I recommend looking at http://web2py.com/book/default/chapter/03 and http://web2py.com/book/default/chapter/04#Dispatching. If you're coming from PHP, you might also look at http://www.web2py.com/AlterEgo/default/show/106. > > In web2py, you don't call (or redirect to) views directly. Instead, all requests are handled by controllers (and the functions within the controllers). A URL of the form '/app/c/f' calls the function 'f()' in the controller 'c.py' in the application 'app'. If f() returns a string, then no view is called, and the string is simply returned as the response. If f() returns a Python dictionary, then web2py looks for a view file with the same name as the function (if the controller is 'c.py', web2py expects to find the view file in a folder named 'c' inside the 'views' folder). If the URL does not include an extension for 'f', then web2py assumes an .html extension for the view file. > > Taking your example, if you want someone to go to 'different_controller/protected_page', inside your 'controllers' folder, you need a 'different_controller.py' file that includes a 'protected_page()' function. Assuming it's an HTML page, there should also be a 'different_controller' folder inside your 'views' folder, and that folder should include a 'protected_page.html' view file to render the output of the 'protected_page()' function. > > Note, if you want to redirect someone to a particular page, you cannot simply set response.view to a different value -- that will just tell the current function to render it's output using a different view -- it will not call the function associated with the different view. To redirect, use the 'redirect' command (http://web2py.com/book/default/chapter/04#HTTP-and-redirect), and specify the page using the URL() function (http://web2py.com/book/default/chapter/04#URL). > > Hope that helps. > > Anthony > > > On Saturday, March 26, 2011 12:15:24 AM UTC-4, james c. wrote: > Hi I'm new to web2py. I've made great progress in a few days with my project. SUMMARY: for every view I call, I get default.py as the controller. Even if I specify app/view/view or app/namediffernt/view I still get default.py as the controller. I appreciate any ideas or pointers on what to try. thanks in advance, james MORE DETAIL: I've read the documentation and here and tried some different approaches. The app is something like this: Anyone can access the hello page and sub pages(page1, page2, page3, ... page7) none of these pages require log in and present static content. A registered user can log-in and access and update contents of a database. In menu.py and (default.py, under def index() { I check if the user is logged-in. if so the I send them off to the protected page, by using logged in, if so they are sent off to their view via: response.view='protected_page.html'. I've also tried response.view='different_controller/protected_page' . First I was trying with the controller and the view html page having the same name. I read under some conditions that may not work so as shown in my example I'm using a controller with a different name from the view. I've tried also putting this in menu.py. and tried putting {{response.view=different_controller/...ect}} into the view.html I also tried using redirect and URL with no success. Every case I ended up either breaking the application or the no matter or with default.py. (regardless of what controller explicitly specified) If I just put all the logic in default.py I can probably getting it working. But I would like to understand what is going on and structure the application appropriately. Sorry for the rambling, but am somewhat sleep deprived from working on this continuously the past three days. I appreciate any recommendations on what to look at or try. Thanks in advance. James >
Thanks Anthony, Jonathan, and Pbreit. Thanks for all your advice, It helped. The key bits are: 1) the html view is named the same as the function; 2) the html view is placed in a separate folder within the views folder and this new folder is named the same name as the controller; and 3) use redirect URL. For anyone that might search at a later time regarding the same: Within the default.py controller I added code to the function def index(): that checks if the user is logged-in and if so then: redirect(URL(r=request, c='my_account', f='summary')) In controllers I created a new controller my_account.py with a function that looks something like: def summary(): if user is logged in then: now=time.ctime() return dict(time=now, here='from happy happy my_account land') else: return dict() In the views folder, I created a new folder with the same name as the controller, my_account. And within the my_account folder, I placed the view html file with the same name as the function: summary.html. Within the summary.html file, in the appropriate places there are two pieces of code within html that looks something like: At <b>{{=time}}</b>, the great and mighty Summary Function has done work and sent results to be displayed here {{=here}}.