V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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
python30
V2EX  ›  Python

django 未读消息提醒,同样的代码。为什么在本地就可以。一部署上服务器就不行了? 代码如下

  •  
  •   python30 · 2019-01-04 14:01:34 +08:00 · 3154 次点击
    这是一个创建于 1911 天前的主题,其中的信息可能已经有所发展或是发生改变。
    models.py








    views.py





    html

    {% for notice in notice_list %}
    {{notice.id}}
    {{  notice.content_object.pub_date|timesince  }}
    {{notice.sender}}
    {% ifequal notice.n_type 1 %}
    <a href="{% url 'bbs:bbs_detail' notice.content_object.topic.id %}"> {{notice.content_object.topic.title}}</a>
    {% else %}
    <a href="{% url 'bbs:bbs_detail' notice.content_object.topic.id %}"> {{notice.content_object.topic.title}}</a>
    <font color="red">@了你</font>:
    {% endifequal %}
    {{  notice.content_object.pub_date|date:"Y-m-d H:i" }}
    {% endfor %}



    不知什么原因。在本地测试中好好的
    一上传到服务器部署到 centos django+nginx+uwsgi 上就。不产生这个消息提醒了?
    20 条回复    2019-01-06 19:18:04 +08:00
    Mohanson
        1
    Mohanson  
       2019-01-04 16:13:00 +08:00 via Android   ❤️ 3
    把服务器搬到工位上,就能本地运行了
    python30
        2
    python30  
    OP
       2019-01-04 18:34:08 +08:00
    @Mohanson 不明白什么意思?
    Vegetable
        3
    Vegetable  
       2019-01-04 18:36:25 +08:00
    玄学 debug 最为致命,这个理论上来说是不可能的,环境上判断数据库可能会有区别你没留意到,还有可能某些地方你吃掉了不该吃掉的异常.
    看这些没办法帮你找问题
    python30
        4
    python30  
    OP
       2019-01-04 19:40:26 +08:00
    @Vegetable


    我把代码简化成这样了

    不知道怎么在服务器上一步步的调试。看在哪一步出的问题?
    Lihz
        5
    Lihz  
       2019-01-04 19:49:17 +08:00
    @python30
    import pdb
    pdb.set_trace()
    python30
        6
    python30  
    OP
       2019-01-04 21:54:24 +08:00
    @Lihz 多谢。
    WilliamYang
        7
    WilliamYang  
       2019-01-05 00:22:38 +08:00
    我没怎么细看你的代码, 你是发邮件通知发不到吗?
    fanhaipeng0403
        8
    fanhaipeng0403  
       2019-01-05 00:31:21 +08:00
    ipython manage.py shell

    %debug
    shanghj
        9
    shanghj  
       2019-01-05 01:48:14 +08:00 via iPhone
    检查一下端口,看相关端口服务器有没有放行,看一下 Django 的配置文件,看是不是因为服务器和本地机器环境有不同,导致配置文件失效。这些都检查后再检查相关功能模块。
    好久没用过 Django 了,有些专业术语想不起了。求不被打。
    qqxx520
        10
    qqxx520  
       2019-01-05 06:44:16 +08:00 via iPhone
    if reply.pub_date==reply.up_date 这句不一定相等,两个字段初始化时,是依次调用当前时间然后保存到数据库的,调用了两次 now(),前一次的 now 和后一次 now 理论上不想等。

    建议如果要判断是第一次 save reply,可以用 post_save 的 created 参数来判断

    https://github.com/django/django/blob/stable/1.11.x/django/db/models/signals.py
    gini0
        11
    gini0  
       2019-01-05 09:30:06 +08:00 via iPad
    目测初始化问题
    neptuno
        12
    neptuno  
       2019-01-05 11:05:12 +08:00 via Android
    可能是哪张表数据的问题吧
    jinhan13789991
        13
    jinhan13789991  
       2019-01-05 11:19:19 +08:00
    上 docker~ 保证没问题
    julyclyde
        14
    julyclyde  
       2019-01-05 13:49:41 +08:00   ❤️ 1
    @jinhan13789991 你这种回答往往意味着你根本不懂技术
    jinhan13789991
        15
    jinhan13789991  
       2019-01-05 14:48:39 +08:00
    @julyclyde #14 我的意思是,docker 能避免因为环境不同而引发的各种问题。
    julyclyde
        16
    julyclyde  
       2019-01-05 15:13:24 +08:00
    @jinhan13789991 不去检查到底哪儿的问题,而简单的逃避问题
    haddy
        17
    haddy  
       2019-01-05 21:28:01 +08:00
    楼主的代码中似乎有一处 except: pass。如果条件允许的话,或许可以把此处改成 except BaseException as e: print e,或者用 logging 保存下来等等,看看有没有报错信息。一个尝试点,不一定能够发现什么,但可以试试。
    haddy
        18
    haddy  
       2019-01-05 21:33:07 +08:00
    抱歉,我没仔细看清楚,请不要在意我刚才的回复。
    haddy
        19
    haddy  
       2019-01-05 21:37:21 +08:00
    看清楚了,的确是有一处裸 except 😂。可以试试我刚才说的点。
    python30
        20
    python30  
    OP
       2019-01-06 19:18:04 +08:00
    @qqxx520 多谢。已经解决了。确实是这个原因。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2479 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 15:45 · PVG 23:45 · LAX 08:45 · JFK 11:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.