I read Yannic's thread here:
http://groups.google.com/group/web2py/browse_thread/thread/701ea73868f72c42
but I still am running into some of the same issues.
First, my default.py controller code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
# # sample index page with internationalization (T)
def index():
data = db().select( \
db.object.user, \
db.object.type, \
db.object.name, \
db.object.description, \
orderby=db.object.name \
)
return dict(data=data)
auth.settings.on_failed_authorization=URL(r=request,f='error')
auth.settings.login_url=URL(r=request,f='login')
@auth.requires_login():
def create():
"""creates new object"""
form=SQLFORM(db.object,fields=['type','name','description'])
if form.accepts(request.vars,session):
session.flash='Object created'
redirect(URL(r=request,f='index'))
elif form.errors:
response.flash='Object not saved'
return dict(form=form)
def login():
return dict(form=auth.login(next='profile'))
def error():
return dict(message = T("not authorized"))
def user():
return dict(form=auth())
def data():
return dict(form=crud())
def download():
return response.download(request,db)
This produces an error ticket:
Traceback (most recent call last): File "gluon/restricted.py", line
97, in restricted File "C:/web2py/applications/QTRAX/controllers/
default.py", line 18 @auth.requires_login
(): ^SyntaxError: invalid syntax
In file: C:\web2py\applications\myapp/controllers/default.py
#!/usr/bin/python# -*- coding: utf-8 -*-#
# sample index page with internationalization (T)
def index(): data = db().select( \
db.object.user, \
db.object.type, \
db.object.name, \
db.object.description, \
orderby=db.object.name \
)
return dict(data=data)
auth.settings.on_failed_authorization=URL(r=request,f='error')
auth.settings.login_url=URL(r=request,f='login')
@auth.requires_login():
def create():
"""creates new object"""
form=SQLFORM(db.object,fields=['type','name','description'])
if form.accepts(request.vars,session):
session.flash='Object created'
redirect(URL(r=request,f='index'))
elif form.errors:
response.flash='Object not saved'
return dict(form=form)
def login(): return dict(form=auth.login(next='profile'))
def error(): return dict(message = T("not authorized"))
def user(): return dict(form=auth())
def data(): return dict(form=crud())
def download(): return response.download(request,db)
response._vars=response._caller(user)
If I remove the : after @auth.requires_login() then I get this error
message:
Traceback (most recent call last):
File "gluon/restricted.py", line 98, in restricted
File "C:/web2py/applications/QTRAX/controllers/default.py", line 46,
in <module>
File "gluon/globals.py", line 75, in <lambda>
File "C:/web2py/applications/QTRAX/controllers/default.py", line 36,
in user
File "gluon/tools.py", line 398, in __call__
File "gluon/tools.py", line 524, in login
AttributeError: 'NoneType' object has no attribute 'fields'
Any thoughts? Why do I have to drop the : after the decorator? Also,
what does the new error message mean?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---