考虑到这是djangorestfranewokr decorator所包含的ajax函数,调试不起作用,django不记录任何错误,当出现问题时,我只有500条信息,如何调试这种在本地工作但在生产中不起作用的大代码。或者Django必须记录错误,然后出了什么问题?

@api_view(['POST', ])
def load_dialog(request):
    if request.method == 'POST':
        party_id = request.data['party_id']
        ticket_id = request.data['ticket_id']
        party = UserProfile.objects.get(pk=party_id)
        ticket = Ticket.objects.get(pk=ticket_id)
        try:
            dialog = Dialog.objects.get(Q(sales=party) | Q(sales=request.user.userprofile))
        except Dialog.DoesNotExist:
            dialog = None
        if dialog:
            textbool = None
            if dialog.sales == request.user.userprofile:
                textbool = "show"
            messages = Message.objects.filter(dialog=dialog)

            s_messages = serializers.serialize('json', messages)
            s_textbool = json.dumps(textbool)
            s_dialog_id = json.dumps(dialog.id)
            data = {
               'messages': s_messages,
               'sales': s_textbool,
               'dialog_id':s_dialog_id,
            }
        else:
            owner = ticket.ownership
            new_dialog = Dialog.objects.create(buyer=request.user.userprofile,sales=owner,ticket=ticket)
            textbool = None
            if new_dialog.sales == request.user.userprofile:
                textbool = "show"
            messages = Message.objects.filter(dialog=new_dialog)
            s_messages = serializers.serialize('json', messages)
            s_textbool = json.dumps(textbool)
            s_dialog_id = json.dumps(new_dialog.id)
            data = {
               'messages': s_messages,
               'sales': s_textbool,
               'dialog_id':s_dialog_id,
            }
    else:
        error = "Fuck"
        return error
    return Response(data)

最佳答案

在生产中,您可以使用ADMINS设置通过电子邮件启用Error Reporting

09-26 05:30