Re: [web2py] How to generate URLs for each user similar to twitter?

2013-11-13 Thread Jonathan Lundell
On 13 Nov 2013, at 1:44 AM, Noah  wrote:

> I understand that Web2Py's urls work like this: 
> 127.0.0.1:9292///
> 
> I'm building an app that has user logins and I want to have a sort of profile 
> page for each user that has an easy to remember URL. Similar to on twitter 
> where to go to a user's page you just navigate totwitter.com/. How 
> does one achieve this using Web2Py?
> 
> Currently I have it working so that the Username is a GET parameter and the 
> URL looks like: 
> 127.0.0.1:9292//Users/Wall?UserName=Thomas1 
> Where 'Users' is the Controller and 'Wall' is the function.
>   
> I want it to be: 127.0.0.1:9292//Users/Thomas1

The parametric router should be able to help you out. 

Define a router for your app that includes something like this. I'll call the 
app 'Noah'.

routers = dict(

# base router
BASE=dict(
default_application='Noah',
),

Noah=dict(
default_controller = 'YouPick',   # this *could* be 'Users', of course, 
if you want to leave it out of your URLs: http://mydomain.com/Thomas1.
default_function = dict(
Users='Wall',
...
),
   functions = dict(
Users=['Wall', 'Index', 'Whatever'],
...
   ),
),
)

By making default_function a dictionary, you can specify a different default 
function per controller. If that's not important to you, you can just make it a 
string and give each controller the same default function.

Listing functions per controller gives the router enough information that it 
can recognize that 'Thomas1' in your example is not a function name. You might 
want to name functions in Users such that you'd never encounter a user by that 
name (or reserve those names in your registration process).

The general idea is that you have to give the router enough information that it 
can unambiguously parse your incoming URLs.

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] How to generate URLs for each user similar to twitter?

2013-11-13 Thread Noah
I understand that Web2Py's urls work like this: 
127.0.0.1:9292///

I'm building an app that has user logins and I want to have a sort of 
profile page for each user that has an easy to remember URL. Similar to on 
twitter where to go to a user's page you just navigate to 
twitter.com/. How does one achieve this using Web2Py?

Currently I have it working so that the Username is a GET parameter and the 
URL looks like: 
127.0.0.1:9292//Users/Wall?UserName=Thomas1 
Where 'Users' is the Controller and 'Wall' is the function.
  
I want it to be: 127.0.0.1:9292//Users/Thomas1

Thanks for your help.

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.