0

I created a redirect URI to help me hook up my app with the Spotify api. I'm using the instructions provided here

I created a callback function in my default controller that is supposed to lead to the redirect URI, an html file I stored as views/default/callback.html

This is how the code in my default controller looks:

def callback():
    redirect(URL('callback.html'))

I set the return URI in my javascript to be http://127.0.0.1:8000/uno/default/callback

When callback is called I am succesfully redirected to http://127.0.0.1:8000/uno/default/callback.html

which I would think is the place where my view (from views/default/callback.html) is located. However, the callback page isn't rendered at all. Instead I get a 303 error for URL redirection. The web2py console isn't very informative. It just says INFO:uno:====> Request: 'GET' '/uno/default/callback.html' [] <Storage {}>

I know I'm missing something very simple and I just can't understand what's going very well.

Any advice?

user2030942
  • 215
  • 5
  • 25

1 Answers1

0

You are misunderstanding how web2py works. web2py URLs have the format /application/controller/function.extension. When web2py receives a request, it looks for the controller and function specified in the URL and then calls the function. If the function returns a dictionary, it then looks for an associated view, and if the view exists, it executes the view (passing to it the values in the dictionary returned by the function) and returns the resulting response to the browser. The extension in the URL is simply used to identify the particular view -- it is optional and defaults to "html". It may help if you read the documentation -- in particular, look here and here.

Your callback() function redirects to /uno/default/callback.html. However, that simply calls the very same function. The only difference between the initial /uno/default/callback and the subsequent /uno/default/callback.html is that the latter explicitly specifies that the view should have a .html extension, whereas the former simply defaults to the .html extension. Because the callback() function never returns a dictionary, the view is never executed. Instead, you enter an infinite loop of redirects back to the same function.

Instead, your callback function should probably look something like:

def callback():
    return dict()

In that case, when the /uno/default/callback URL is requested, web2py will execute the callback.html view and return the resulting content to the browser. If that is not what you need, then you should probably post a new question explaining what you are trying to achieve.

Anthony
  • 25,466
  • 3
  • 28
  • 57