How to use try..except, but when DEBUG is True, show the error?

已查看 12 次
跳至第一个未读帖子

Fellipe Henrique

未读,
2017年8月12日 10:55:002017/8/12
收件人 Django Users
Hello,

i have these code, for example:
try:
   x = parse_date('xxxx')
except TypeError:
  return False

 It's ok for me code like these.. but, when DEBUG == True, I like to show the django default error page...

How can I do that?

Regards

T.·.F.·.A.·.     S+F
Fellipe Henrique P. Soares

e-mail: > echo "lkrrovknFmsgor4ius" | perl -pe \ 's/(.)/chr(ord($1)-2*3)/ge'
Twitter: @fh_bash

Jani Tiainen

未读,
2017年8月12日 11:27:592017/8/12
收件人 django...@googlegroups.com
You can reraise exception simply by calling "raise" without params.

--
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...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAF1jwZF%2Bf2KAZjNWA%2BjVnhTKbSj-vQQ4WjQRUzsr5vCxrqg4Eg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Vijay Khemlani

未读,
2017年8月12日 11:29:252017/8/12
收件人 django...@googlegroups.com
from django.conf import settings

try:
   x = parse_date('xxxx')
except TypeError:
  if settings.DEBUG:
    raise
  else:
    return False


--

Marcin Gałązka

未读,
2017年8月12日 11:33:132017/8/12
收件人 django...@googlegroups.com
> Hello,
>
> i have these code, for example:
>
> try:
> x = parse_date('xxxx')
> except TypeError:
> return False
>
​>
>
> It's ok for me code like these.. but, when DEBUG == True, I like to show the django default error page...
>
> How can I do that?
>
> Regards

Why not simply re-raise the exception?

from yourproject.settings import DEBUG

try:
x = parse_date('xxxx')
except TypeError:
if DEBUG:
raise
return False

Fellipe Henrique

未读,
2017年8月12日 11:52:192017/8/12
收件人 Django Users
Thanks, but.. it's  weird I tried that before, and show me the error, but, only text.. not that "yellow page" from django...

I'll look again my code...

Thanks again!

T.·.F.·.A.·.     S+F
Fellipe Henrique P. Soares

e-mail: > echo "lkrrovknFmsgor4ius" | perl -pe \ 's/(.)/chr(ord($1)-2*3)/ge'
Twitter: @fh_bash

--
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...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Jani Tiainen

未读,
2017年8月12日 12:02:502017/8/12
收件人 django...@googlegroups.com
Also I would suggest that you log exception in case you don't want to raise it. That way you know that something goes wrong.

回复全部
回复作者
转发
0 个新帖子