On Apr 6, 2011, at 9:45 AM, Massimo Di Pierro wrote:
>
> This should probably be changed to
>
> p.error_message = '<html><body><h1>%(error_message)s</h1></body></
> html>'
>
> def fix(text): return text.replace('%s','%(error_message)s')
>
> raise HTTP(404,
> fix(rewrite.thread.routes.error_message) %
> dict(error_massage='invalid request'),
> web2py_error='invalid application')
What's the expected use case for overriding error_message?
>
> On Apr 6, 11:21 am, Jonathan Lundell <[email protected]> wrote:
>> On Apr 5, 2011, at 7:33 PM, pbreit wrote:
>>
>>> I uncommented the "error_message" config in my global routes.py file and it
>>> broke my whole site. It seemed to block stylesheets from loading but some
>>> site content actually did load. "error_message_ticket" works OK. Is anyone
>>> using this successfully?
>>
>> The problem, I think, is that the example error_message isn't a valid
>> replacement. The example string is:
>>
>> # error_message = '<html><body><h1>Invalid request</h1></body></html>'
>>
>> But the internal default message is this:
>>
>> p.error_message = '<html><body><h1>%s</h1></body></html>'
>>
>> and it gets used like this:
>>
>> raise HTTP(404,
>> rewrite.thread.routes.error_message %
>> 'invalid request',
>> web2py_error='invalid application')
>>
>> Notice that the string must contain exactly one format element, %s.
>> Otherwise Python will raise TypeError.
>>
>> (One of these days will have the T function working in gluon, and these
>> messages can be localized.)