views:

45

answers:

2

Hi,

I started playing around with web2py the other day for a new project. I really like the structure and the whole concept which feels like a breath of fresh air after spending a few years with PHP frameworks.

The only thing (currently) that is bothering me is the ticketing system. Each time I make a misstake a page with a link to a ticket is presented. I guess I could live with that if the link worked. It currently points to an admin page with http as protocol instead of https. I've done a bit of reading and the forced https for admin seems to be a security measure, but this makes debugging a pain.

Whats the standard solution here? Alter the error page, allow http for admin och use logs for debugging?

Best regards Fredrik

+1  A: 

I was in the same boat as you, I did not like the default mechanism. Luckily, customized exception handling with web2py is very straightforward. Take a look at routes.py in the root of your web2py directory. I've added the following to mine:

routes_onerror = [('application_name/*','/application_name/error/index')]

This routes any exceptions to my error handler controller (application_name/controllers/error.py) in which I defined my def index as:

def index():
    if request.vars.code == '400':
        return(dict(app=request.application,
            ticket=None,
            traceback="A 400 error was raised, this is controller/method path not found",
            code=None,
            layer=None,
            wasEmailed=False))
    elif request.vars.code == '404':
        return(dict(app=request.application,
            ticket=None,
            traceback="A 404 error was raised, this is bad.",
            code=None,
            layer=None,
            wasEmailed=False))  
    else:
        fH = file('applications/%s/errors/%s' % (request.application,request.vars.ticket.split("/")[1]))
        e = cPickle.load(fH)
            fH.close()
            __sendEmail(request.application,e['layer'],e['traceback'],e['code'])
        return(dict(app=request.application,
            ticket=request.vars.ticket,
            traceback=e['traceback'],
            code=e['code'],
            layer=e['layer'],
            wasEmailed=True))

As you can see for non-400 and 404 errors, I'm emailing the traceback to myself and then invoking the corresponding views/error/index.html. In production, this view gives a generic "I'm sorry an error has occurred, developers have been emailed". On my development server, it displays the formatted traceback.

Mark
Thanks for the quick reply Mark, that seems like a good solution!
Fredrik
A: 

Normally, I just use http://127.0.0.1/ (if you are local or over ssh) or edit/navigate using https://...

So, you will logon the admin app the first time, but always will the show the tickets after.

Alexandre Andrade