On Tuesday, May 17, 2016 at 5:10:25 AM UTC-4, Vic Ding wrote:
>
> Strange enough. Found the code which is generating the 404 problem. 
>
> If I use crud. The record will be removed, but a 404 error to 
> default/removeProduct error will raise. 
>
> crud.delete(db.product, productid)
>
>
> If I use delete, everything works fine. but I do not get the flash 
> confirmation "record removed"
>
> db(db.product.id == productid).delete()
>
>
The problem is that Crud automatically does a redirect after each of its 
actions, and by default, it redirects to the current function, but it 
assumes the controller is default.py. So, you would have to change it by 
setting crud.settings.delete_next = URL(...).

The redirect really isn't necessary, though, and the only way to avoid it 
would be to specify a crud.settings.delete_onaccept callback and raise an 
HTTP() exception to immediately return a 200 response.

crud.delete() is also somewhat inefficient, as it first retrieves the 
record from the database before deleting it (not sure why).

Ultimately, you're probably better off with db(...).delete() rather than 
using Crud. In fact, Crud is generally not recommended anymore, as most of 
its functionality has been subsumed by SQLFORM.process() and SQLFORM.grid().

Anthony

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to