如何在Django中调试Ajax请求 [英] How to debug the ajax request in django

查看:47
本文介绍了如何在Django中调试Ajax请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道例如:

def home(request):
    if request.method == 'POST':
        k = 'p' % 1
        return HttpResponse(simplejson.dumps(dict()),  mimetype='application/javascript')
    else:
        k = 'p' % 1
        return render_to_response('index.html',locals());

url(r'^$', 'app.home'),

如果我使用浏览器访问主页,django将向我返回一个调试页面,并显示 k ='p'%1

If I use the browser to visit the home page, django will return a debug page to me and show that there is an error in k = 'p' % 1

但是,如果我使用 $.ajax()向此视图发送帖子,则chrome控制台仅显示 POST http://(此处为某些网址):8000/500(内部服务器错误)

But if I use the $.ajax() to send a post to this view, the console of chrome only show POST http://(some url here):8000/ 500 (INTERNAL SERVER ERROR)

那么有什么好的方法可以调试第二种情况?我不知道如何调试django,有没有人有更好的调试django的方法?

so is there any good way to debug the second case? I have no idea about debug the django, is there anybody have better way to debug the django?

谢谢

推荐答案

看看 sentry (和相应的乌鸦)

( Network 选项卡应该能够向您显示请求和相应的响应.我相信较新的django版本甚至可以在请求为ajax的情况下为您提供更多的stacktrace版本)

(the Network tab should be able to show you the request and the corresponding response. i believe newer django versions even give you a more bare-bones version of the stacktrace if the request was ajax)

这篇关于如何在Django中调试Ajax请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆