【问题标题】:How to get info on Django HTTP 500 error如何获取有关 Django HTTP 500 错误的信息
【发布时间】: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 模式下运行才能获取信息吗?

【问题讨论】:

标签: python django nginx django-views uwsgi


【解决方案1】:

将user = request.user 也放在try-catch 块中。

尝试记录请求以检查标头。

【讨论】:

    猜你喜欢
    • 2011-03-17
    • 2013-11-16
    • 2015-12-09
    • 1970-01-01
    • 2012-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多