【发布时间】:2015-06-11 08:20:05
【问题描述】:
我在 nginx/uWSGI 上运行一个 Django 1.8 站点。
在./manage.py runserver 上,一切都按预期工作,但是当我将其移至生产环境时,一些视图返回 HTTP 500 错误。
查看 uWSGI 日志,我得到如下信息:
** View: booking_accept_view 6zN6
[pid: 1959|app: 0|req: 7/7] xxx.xxx.xxx.xxx () {56 vars in 1339 bytes}
[Thu Jun 11 10:00:39 2015] GET /tidsbestilling/admin-accept/6zN6/ =>
generated 27 bytes in 28 msecs (HTTP/1.1 500)
6 headers in 226 bytes (2 switches on core 0)
所以这里没有太多帮助。
nginx访问日志:
xxx.xxx.xxx.xxx - - [11/Jun/2015:10:00:39 +0200]
"GET /tidsbestilling/admin-accept/6zN6/ HTTP/1.1" 500 38
"https://example.com/tidsbestilling/admin-details/6zN6/"
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/600.7.10
(KHTML, like Gecko) Version/8.0.7 Safari/600.7.10"
nginx 错误日志中没有条目。
我尝试将其包含在 try-except 块中,但我没有从中得到任何信息。
我的观点是这样的:
def booking_admin_accept_view(request, booking_uid):
print("** View: booking_accept_view", booking_uid)
user = request.user
if not (user is not None and user.is_authenticated() and user.is_active):
return HttpResponseRedirect(reverse('booking_admin_login_view'))
try:
booking = Booking.objects.get(uid=booking_uid)
booking.status = 'accepted'
booking.save()
send_sms(booking)
return HttpResponseRedirect(reverse('booking_admin_details_view', args=(booking_uid,)))
except(Exception, e):
logging.exception(e)
booking.save() 被执行,如果我执行./manage.py shell,我可以执行send_sms(booking),这也可以,但视图并没有那么远。
所以我的问题是:我如何获得有关问题所在的更多信息?我真的必须在 DEBUG 模式下运行才能获取信息吗?
【问题讨论】:
-
你提到了 uWSGI 日志……你检查过 Nginx 日志了吗?
-
500 个错误由 django 记录。有什么说法吗?
-
@rnevius:我把 nginx 访问日志条目放在了问题中,但这里也没有太大帮助。
-
Django 能够在生产中通知您致命错误。您是否设置了
ADMINS变量?请阅读docs.djangoproject.com/en/1.8/howto/error-reporting,可能最重要的是还引用了docs.djangoproject.com/en/1.8/ref/settings/#std:setting-ADMINS
标签: python django nginx django-views uwsgi