Issue with web2py load component

120 views
Skip to first unread message

Gaurav Vichare

unread,
Jan 12, 2017, 12:35:41 PM1/12/17
to web2py-users
I have LOAD component in my application. I made changes in web2py/routes.py file and made my application default application, 'default' controller and 'index' function as defaults. Also added function list of default.py controller in routes.py to distinguish between args and function name(https://groups.google.com/d/msg/web2py/yi5rPK4APKs/rVBg9AiShPUJ). Now when I open my app (http://127.0.0.1:8000/  or http://127.0.0.1:8000/test/default/index), load component div loads complete app in it, and this goes in loop. 

Here is routes.py and minimal code
#routes.py

routers = dict(

    # base router
    BASE=dict(
        default_application='test',
        default_controller = 'default',
        default_function = 'index',
        functions = ['index', 'user', 'download', 'call',
                     'test_load'],
    ),
)

--------------
# default.py
def index():
    return dict(message=T('Welcome to web2py!'))

def test_load():
    return dict(message=T('This is sample component'))
-----------
# Views
<!--index.html-->
{{extend 'layout.html'}}
<h2>{{=message}}</h2>
{{=LOAD('default','test_load.load',ajax=True)}}


<!--test_load.load-->
{{=message}}

Screenshot:


Please help me to solve this issue.

Thank You
- Gaurav

Leonel Câmara

unread,
Jan 13, 2017, 8:24:53 AM1/13/17
to web2py-users
Are you sure test_load.load doesn't have an {{extend 'index.html'}there?

Gaurav Vichare

unread,
Jan 13, 2017, 9:05:21 AM1/13/17
to web2py-users
There is no  {{extend 'index.html'}} in test_load.load.  

I faced similar issue once, when I added {{extend 'layout.html'}} inside load view. But this time, I have  {{extend 'layout.html'}} only in index.html
Thanks for the reply!

Anthony

unread,
Jan 13, 2017, 10:04:42 AM1/13/17
to web2py-users
Please attach a minimal app that reproduces the problem (along with routes.py).

Gaurav Vichare

unread,
Jan 13, 2017, 10:51:03 AM1/13/17
to web2py-users
I was unable to access http://127.0.0.1:8000/admin as well, so I first removed attached routes.py and then created w2p package. Chrome gave error "Too many redirects".

Please find attached minimal app and web2py/routes.py file.
I am using web2py 2.14.6

Thank You
web2py.app.test.w2p
routes.py

Anthony

unread,
Jan 13, 2017, 4:12:27 PM1/13/17
to web...@googlegroups.com
I consider this a router bug. The problem is that the list of functions must include the function.extension combination in cases where URLs might include extensions. So, in the router, change:


        functions = ['index', 'user', 'download', 'call', 'test_load']

to:

        functions = ['index', 'user', 'download', 'call', 'test_load.load']

More, generally, if you plan to call a given function with multiple extensions (and possibly no extension), you must include all possibilities:

            functions = ['myfunc', 'myfunc.load', 'myfunc.json', 'myfunc.xml']

I made a pull request to fix this: https://github.com/web2py/web2py/pull/1558

Anthony

Gaurav Vichare

unread,
Jan 14, 2017, 1:33:56 AM1/14/17
to web2py-users
Thank You so much Anthony, It worked :)

- Gaurav

Gaurav Vichare

unread,
Jan 14, 2017, 12:43:43 PM1/14/17
to web2py-users
Now my app is working without any issues, but i am still not able to access admin (http://127.0.0.1:8000/admin/). 


On Saturday, January 14, 2017 at 2:42:27 AM UTC+5:30, Anthony wrote:

Anthony

unread,
Jan 14, 2017, 3:01:39 PM1/14/17
to web2py-users
On Saturday, January 14, 2017 at 12:43:43 PM UTC-5, Gaurav Vichare wrote:
Now my app is working without any issues, but i am still not able to access admin (http://127.0.0.1:8000/admin/). 

What happens when you go to that URL?

Gaurav Vichare

unread,
Jan 14, 2017, 11:49:37 PM1/14/17
to web2py-users
Page for login to administrative interface opens without issue, but when I login, chrome give me following error

The 127.0.0.1 page isn’t working

127.0.0.1 redirected you too many times.

ERR_TOO_MANY_REDIRECTS1

Clearing cookies doesn't work.
And on firefox, I am redirected to same admin login page.

Thank You

Anthony

unread,
Jan 15, 2017, 1:04:39 PM1/15/17
to web2py-users
You're router specifies only a BASE element, which will apply to all applications, including admin -- but it should only apply to your specific application. So, change it to something like:

routers = dict(
    BASE
=dict(
        default_application
='test')
   
),
    test
=dict(

        default_controller
= 'default',
        default_function
= 'index',

        functions
= ['index', 'user', 'download', 'call', 'test_load.load']
   
)
)

Anthony

Gaurav Vichare

unread,
Jan 16, 2017, 12:06:22 PM1/16/17
to web2py-users
Got it!
Thank You so much Anthony.
Reply all
Reply to author
Forward
0 new messages