django简单的调试给出了奇怪的结果

时间:2017-02-10 11:17:29

标签: django

我在项目中遇到了一些有趣的事情,我使用的是Oracle作为数据库。在js里面我调用home视图函数时会发生奇怪的事情。怎么会发生?

JS

setInterval(function() {
    var div = document.querySelector("#counter");
    var count = div.textContent * 1 - 1;
    div.textContent = count;
    if (count <= 0) {
        window.location.href="{% url 'home' %}";
    }
}, 1000);

def home(request):
# First check IP address
if request.user == AnonymousUser():
    ip_address  = get_ip_address(request)
    user_logged = login_ip_address(request,ip_address,request.user)

if request.user.is_authenticated:
    print "1"
    getNotifications(request)
    print "2"
    requests = getRequests(request)
    print "3"
    user_categories_names = getUserCategories(request)
    print "4"
    chart = []

    if requests:
        print "5"
        openR = requests.filter(status="open").count()
        print "6"
        closedR = requests.filter(status="closed").count()
        print "7"
        lockedR = requests.filter(status__contains="lock").count()
        print "8"
        if openR>0 or closedR>0 or lockedR>0:
            print "9"
            chart=[openR,closedR,lockedR]
            print "10"
        else:
            print "11"
            deletedR = requests.filter(status="deleted").count()
            chart=[deletedR]
    #allCategoryRequests = getAllCategoryRequests(request,user_categories_requests)

    #requests = list(chain(sentRequestResult, tagRequests, parentRequestResult))
    print "12"
    data = {'requests':requests,'catNames':user_categories_names,'chart':chart,'activeCategory':'taggedRequests'}
    template = "home.html"
    print "13"
    #pdb.set_trace()
    return render(request,template,data)
    print "14"
else:
    print "15"
    return HttpResponseRedirect('accounts/login')

输出

1 1 1 1 1 1 1  1 1 1  1 1 2 3 1 1 4 五 2 3 6 7 4 8  五 9 10 12 13 6 1 7 8 9 10 12 13 2 3 2 3 4 1 2 3 4 五 被杀:9

1 个答案:

答案 0 :(得分:2)

问题出在js中,它发送了多个重定向。所以它应该是if(count == 0)。