tags:

views:

83

answers:

1

django view:

def json_view(request):
    import json
    tag=request.GET.get('tag')
    if tag=='userName':
        username=request.GET.get('userName')
        result='successName'
        if username:
            try:
                user=User.objects.get(username=username)
                result='existName'
            except User.DoesNotExist:
                pass
            return HttpResponse(json.dumps({'result': result}))

    if tag=='email':
        email=request.GET.get('email')
        result='emailSuccess'
        if email:
            try:
                user=User.objects.get(email=email)
                result='notOnly'
            except User.DoesNotExist:
                pass
            return HttpResponse(json.dumps({'result': result}))

1.:

$.getJSON('/json_view/', {
                                tag: "userName",
                                userName: G
                            },
                            function (H) {
                                if (H.result == "successName") {
                                    F.showOk(h.ok);
                                    d = true
                                } else {
                                    if (H.result == "existName") {
                                        F.showErr(h.userNameExist);
                                        d = false
                                    }
                                }
                            })

2.:

$.getJSON('/json_view/', {
                    tag: "email",
                    email: F
                },


                function (G) {
                    if (G.result == "emailSuccess") {
                        E.showOk(h.ok);
                        B = true
                    } else {
                        if (G.result == "notOnly") {
                            E.showErr(h.emailExist);
                            B = false
                        }
                    }
                })

why?

thanks

the error is:

GET http://127.0.0.1:8000/json_view/?tag=email&email=zjm1126%40qq.com 500 INTERNAL SERVER ERROR
+1  A: 

Write a unit test that isolates the problem. Documentation: http://docs.djangoproject.com/en/dev/topics/testing/

The body of the test should be something like:

from django.test.client import Client
c = Client()
response = c.get('/json_view/', {'tag': 'email', 'email': '...'})
codeape