首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >django简单调试产生奇怪的结果

django简单调试产生奇怪的结果
EN

Stack Overflow用户
提问于 2017-02-10 19:17:29
回答 1查看 28关注 0票数 1

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

js

代码语言:javascript
复制
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);

首页

代码语言:javascript
复制
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 2 3 1 1 4 5 2 3 6 7 4 8 5 9 10 12 13 6 1 7 9 10 12 13 2 3 3 4 1 2 3 4 1 2 3 4 5被杀:9

EN

回答 1

Stack Overflow用户

发布于 2017-02-10 19:41:31

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42158087

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档