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
lhy360121
V2EX  ›  Python

django filter(pub_date__year=2015)报错

  •  
  •   lhy360121 · 2015-03-17 09:48:57 +08:00 · 3034 次点击
    这是一个创建于 3322 天前的主题,其中的信息可能已经有所发展或是发生改变。
    有一行代码:
    blog_list = Blog.objects.filter(pub_date__month=2) 这么写没问题,可以获取结果 ,pub_date__day也没问题。

    但是
    blog_list = Blog.objects.filter(pub_date__year=2015) 这样写就报如下错误:

    -----------------------------------------------
    Django Version: 1.7.1
    Exception Type: TypeError
    Exception Value:

    not enough arguments for format string

    Exception Location: D:\Python27\lib\site-packages\MySQLdb\cursors.py in execute, line 187
    Python Executable: D:\Python27\python.exe
    Python Version: 2.7.8
    ------------------------------------------------------

    很费解,代码没错呀,__year 失效了? MySQL-python换成1.2.5也不行。
    tkliuxing
        1
    tkliuxing  
       2015-03-17 11:57:55 +08:00   ❤️ 1
    试一试raw写SQL能不能用。
    lhy360121
        2
    lhy360121  
    OP
       2015-03-17 13:42:03 +08:00
    @tkliuxing 已改成raw获取数据了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2618 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 11:06 · PVG 19:06 · LAX 04:06 · JFK 07:06
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.