推荐学习书目
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 · Mar 17, 2015 · 4019 views
    This topic created in 4080 days ago, the information mentioned may be changed or developed.
    有一行代码:
    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  
       Mar 17, 2015   ❤️ 1
    试一试raw写SQL能不能用。
    lhy360121
        2
    lhy360121  
    OP
       Mar 17, 2015
    @tkliuxing 已改成raw获取数据了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1012 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 22:31 · PVG 06:31 · LAX 15:31 · JFK 18:31
    ♥ Do have faith in what you're doing.