I defined a function in controller file(test.py) the code is:
def user():
return dict(form=auth())
then,when I visit http://localhost:8000/demo/test/user why the url changed to http://localhost:8000/demo/default/user/login automatically?
I defined a function in controller file(test.py) the code is:
def user():
return dict(form=auth())
then,when I visit http://localhost:8000/demo/test/user why the url changed to http://localhost:8000/demo/default/user/login automatically?
When you call the Auth
object via auth()
, it inspects the URL args (i.e., the parts of the URL after the controller and function) in order to determine which Auth method has been requested (e.g., login, register, profile, etc.). If there is no URL arg (as in your case), then it redirects to the same URL as the current one, but with /login appended (otherwise, it would have nothing to return without any specific Auth method having been requested).
If you are going to use the above construction (i.e., a generic user
function that simply calls auth()
), then you should create links that include specific Auth methods as the first URL arg. If for some reason you want the login link to be /user (without any URL arg), you could do something like:
def user():
if not request.args:
form = auth.login()
else:
form = auth()
return dict(form=form)
That will explicitly return the login form when there are no URL args but fall back to the standard behavior otherwise.
You may of course have completely separate actions for each Auth method as well:
def login():
return dict(form=auth.login())
def register():
return dict(form=auth.register())
etc.