[Twisted-web] Newov Login Forward

Andy Gayton andy at thecablelounge.com
Tue Feb 22 05:05:20 MST 2005

noema wrote:

> I think an answer to the following issue could be useful for many 
> people: (1) When I have a login page resource like the one listed here 
> how can I return another page than the root one? (2) How can I return a 
> certain page resource depending on the username?

G'day Noema,

Have a look a guarded.py in the examples directory.  Guard uses the 
realm you've associated with your site's portal to determine which 
object represents your site's root page.

Until the user logs in, guard requests an avatar for the 
checkers.ANONYMOUS user - so your realm usually returns a login page for 
this user.  When a user successfully authenticates themselves with 
guard, guard will ask your realm for an object that matches the user's 

So for 1/ - arrange for your sites realm to return the new root page 
once you have an authenticated userid

for 2/ I'd approach this using components and adaptors.  Represent each 
user type as an implementation of an interface for that user type - for 
example you might have IUser and IUserAdmin.  Then create adaptors from 
the IUser interface to nevow.IResource and IUserAdmin to nevow.IResource.

Your realm can then simply return a user object which is either an 
implementation of IUser or IUserAdmin - and the correct page will be drawn.

These links might be useful:


Hoping I haven't missed what you've actually asked :)


More information about the Twisted-web mailing list