Thanks Anthony.  Everything is working fine now!

On Thursday, May 10, 2012 3:37:53 PM UTC-5, Anthony wrote:
>
> @auth.requires_login()
> def user():
>
> Don't require login to get to the user() function -- if you're not logged 
> in, it redirects to the user() function, which will result in an infinite 
> redirect loop.
>
> Anthony
>
> On Thursday, May 10, 2012 11:33:34 AM UTC-4, man24 wrote:
>>
>> Here is the model file - > db2.py 
>>
>> # coding: utf8
>> db.define_table('page',
>>         Field('title', requires=IS_NOT_IN_DB(db, 'page.title')),
>>         Field('body', 'text', requires=IS_NOT_EMPTY()),
>>         Field('created_on', 'datetime', default=request.now, 
>> readable=False, writable=False),
>>         Field('created_by', db.auth_user, default=auth.user_id, 
>> readable=False, writable=False),
>>         format='%(title)s')
>>         
>> db.define_table('comment',
>>         Field('page_id', db.page, readable=False, writable=False),
>>         Field('body', 'text', requires=IS_NOT_EMPTY()),
>>         Field('created_on', 'datetime', default=request.now, 
>> readable=False, writable=False),
>>         Field('created_by', db.auth_user, 
>> default=auth.user_id,readable=False, writable=False))
>>         
>> db.define_table('document',
>>         Field('page_id', db.page, readable=False, writable=False),
>>         Field('name', requires=IS_NOT_IN_DB(db, 'document.name')),
>>         Field('file', 'upload'),
>>         Field('created_on', 'datetime', default=request.now, 
>> readable=False, writable=False),
>>         Field('created_by', db.auth_user, default=auth.user_id, 
>> readable=False, writable=False),
>>         format='%(name)s')
>>
>> Here is the controller: 
>>
>> def index():
>>     pages = db().select(db.page.id, db.page.title, orderby=db.page.title)
>>     return dict(pages=pages)
>>     
>> @auth.requires_login()
>> def create():
>>     form=crud.create(db.page, next=URL('index'))
>>     return dict(form=form)
>>     
>> def show():
>>     this_page = db.page(request.args(0)) or redirect(URL('index'))
>>     db.comment.page_id.default = this_page.id
>>     form = crud.create(db.comment) if auth.user else None
>>     pagecomments = db(db.comment.page_id==this_page.id).select()
>>     return dict(page=this_page, comments=pagecomments, form=form)
>>
>> @auth.requires_login()
>> def edit():
>>     this_page = db.page(request.args(0)) or redirect(URL('index'))
>>     form = crud.update(db.page, this_page, next=URL('show', 
>> args=request.args))
>>     return dict(form=form)
>>     
>> @auth.requires_login()
>> def documents():
>>     page = db.page(request.args(0)) or redirect(URL('index'))
>>     db.document.page_id.default = page.id
>>     db.document.page_id.writable = False
>>     grid = SQLFORM.grid(db.document.page_id==page.id, args=[page.id])
>>     return dict(page=page, grid=grid)
>>     
>> @auth.requires_login()
>> def user():
>>     """
>>     exposes:
>>     http://..../[app]/default/user/login
>>     http://..../[app]/default/user/logout
>>     http://..../[app]/default/user/register
>>     http://..../[app]/default/user/profile
>>     http://..../[app]/default/user/retrieve_password
>>     http://..../[app]/default/user/change_password
>>     use @auth.requires_login()
>>         @auth.requires_membership('group name')
>>         @auth.requires_permission('read','table name',record_id)
>>     to decorate functions that need access control
>>     """
>>     return dict(form=auth())
>>
>> Here are the views:
>> Index:
>> {{left_sidebar_enabled,right_sidebar_enabled=False,True}}
>> {{extend 'layout.html'}}
>> <h1>Available Wiki Pages</h1>
>> [ {{=A('search', _href=URL('search'))}} ]<br />
>> <ul>{{for page in pages:}}
>>        {{=LI(A(page.title, _href=URL('show', args=page.id)))}}
>> {{pass}}</ul>
>> [ {{=A('create page', _href=URL('create'))}}]
>>
>> Create:
>> {{extend 'layout.html'}}
>> <h1>Create new wiki page</h1>
>> {{=form}}
>>
>> Show:
>> {{extend 'layout.html'}}
>> <h1>{{=page.title}}</h1>
>> [ {{=A('edit', _href=URL('edit', args=request.args))}} ]
>> [ {{=A('documents', _href=URL('documents', args=request.args))}} ]<br />
>> {{=MARKMIN(page.body)}}
>> <h2>Comments</h2>
>> {{for comment in comments:}}
>>   <p>{{=db.auth_user[comment.created_by].first_name}} on 
>> {{=comment.created_on}} says <i>{{=comment.body}}</i></p>
>> {{pass}}
>> <h2>Post a comment</h2>
>> {{=form}}
>>
>> Edit:
>> {{extend 'layout.html'}}
>> <h1>Edit wiki page</h1>
>> [ {{=A('show', _href=URL('show', args=request.args))}} ] <br />
>> {{=form}}
>>
>> documents:
>> {{extend 'layout.html'}}
>> <h1>Documents for page: {{=page.title}}</h1>
>> [ {{=A('show', _href=URL('show', args=request.args))}} ]<br />
>> <h2>Doucments</h2>
>> {{=grid}}
>>
>> Thanks
>>
>>
>> On Thursday, May 10, 2012 6:09:09 AM UTC-5, Anthony wrote:
>>>
>>> Can you post your exact code (models, controllers, views)?
>>>
>>> On Thursday, May 10, 2012 1:22:14 AM UTC-4, man24 wrote:
>>>>
>>>> Sorry for reposting the question.  I am following the 'wiki' example 
>>>> given in the web2py book.  After first implementation, it worked fine, 
>>>> however, now when I click on any action that requires login or even 
>>>> clicking the 'login' from the top menu, I get this response from my web 
>>>> browser:  'too many redirects occurred when trying to open'.  Any idea 
>>>> what 
>>>> could be wrong.  The 'wiki' app was working fine yesterday and I haven't 
>>>> made any changes and now today it's giving this problem.  BTW, I am 
>>>> running 
>>>> web2py on a mac.  Thanks for your help.
>>>
>>>

Reply via email to