Re: How to raise exception in model?
Thanks, that solves my problem.
On Mon, Sep 16, 2013 at 4:38 PM, C. Kirby <misthop@gmail.com> wrote:
If you successfully get to render_to_response (or similar) the template renderer will silently swallow errors.
If you want the error to stop rendering and either print an error or a 500 or something similar, test it in the view before rendering.
Assuming you have an entry (or list of entries I guess) in your view:
for entry in entries: #for a list of entries
try:
entry.state
except:
return HttpResponse(status = 500)
or something similar
On Monday, September 16, 2013 5:36:02 AM UTC-5, Ladislav P wrote:I have some custom functions in model classes which processes some data, and add custom attribute to the model. Thing is, I do not know how could I raise an exception if this functions that are accessed when the template is generated (the error seems to be only silent, so it will process the template further but gives NO ERROR )In the template{{ entry.state }}In the model:@propertydef state(self):somedict = {'a': 111}try:print somedict['b']except Exception as e:FATAL_ERRORWhat should I put in the place of fatal_error so that the template processing should stop immediatelly, or gives some exception to the render function ?Thanks--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home