推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
chengxiao
V2EX  ›  Python

求助一下 关于在 DJango 中的时间筛选

  •  
  •   chengxiao · Nov 28, 2017 · 2996 views
    This topic created in 3226 days ago, the information mentioned may be changed or developed.

    最近在做一个日常打卡的项目,碰到了一点问题,日期到第二天不能正确辨认

    today = timezone.now.date()
    def log:
        log = Logs.object.filter(date=today)
        if log:
            do something
        else:
            do somethng
    

    当我在服务器运行时,第一次打卡是正确的,可是到第二天的时候,理论上应该出现 else 的情况,可是却不出来,必须重启 uwsgi 才可以,请教下这是什么问题呢?

    5 replies  •  2017-11-29 10:59:32 +08:00
    Cynic222
        1
    Cynic222  
       Nov 29, 2017 via iPhone
    虽然没看到完整代码,我觉得 today=...不应该放在 def 外面
    vZexc0m
        2
    vZexc0m  
       Nov 29, 2017
    因为这里的 today 成了定值
    chengxiao
        3
    chengxiao  
    OP
       Nov 29, 2017
    @Cynic222
    @vZexc0m
    似乎是这样 昨晚也发现问题可能出现在这个全局变量上,今天正常啦~
    5oiR5piv5YK76YC8
        4
    5oiR5piv5YK76YC8  
       Nov 29, 2017
    你初始化的时候 today (全局变量)就被定死了,你放在里面的话,每次运行函数才指定 today,所有才正确。
    shuizhengqi
        5
    shuizhengqi  
       Nov 29, 2017
    这种东西只是 python 语法问题,跟 django 没关系。。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1021 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 18:20 · PVG 02:20 · LAX 11:20 · JFK 14:20
    ♥ Do have faith in what you're doing.