On Jun 18, 10:17 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I have a problem about the controller programing.
> I have some java programming background, i like to include the
> operation code block into a try-except block, so, i do the controller
> method like this:
>
> def edit(self, id):
>     return_render = None
>     try :
>         # something for edit and database read or write
>         if form_data_format_error:
>               # re-show the edit form and show the error message on
> the page
>               return_render = render_response('edit_template.myt')
>         else:
>               # write to the database and redirect to the user to the
> list
>               return_render = redirect_to(action='list')
>     except:

You should avoid bare except clauses. In Python, exceptions are not
only for error handling (hint : sys.exit raises an exception to exit
the interpreter).

As a mater of fact, this is the cause of your problem here:
http://pylonshq.com/project/pylonshq/wiki/FAQ#why-do-redirect-to-and-abort-raise-exceptions-instead-of-returning-a-response

>         print sys.exc_info()
>         return_render = render_response('error_exception.myt')
>     return return_render
>
> I know these kind of code has some problem. The redirect_to do not
> work correctly.

It does. That's your try/except block that's preventing the framework
to do it's job.

> Can you help me for the correct way to make this work?

Just get rid of that try/except block - at least until you know which
exceptions you really want to handle at this level. Pylons has great
tools for debugging, you'd probably be better using them instead...

My 2 cents...




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to