推荐学习书目
› 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
larkifly
V2EX  ›  Python

django url 匹配的一个奇怪的错误

  •  
  •   larkifly · May 5, 2014 · 3115 views
    This topic created in 4531 days ago, the information mentioned may be changed or developed.
    url(r'^people\?page=(\d+)$', views.PersonalHome),
    url(r'^people/(\d+)/$', views.PersonalHome),
    如上的两个url配置

    现在
    http://127.0.0.1:8000/people?page=2无法匹配

    http://127.0.0.1:8000/people/3/可以匹配

    错在哪了?
    3 replies  •  2014-05-05 18:11:28 +08:00
    messense
        1
    messense  
       May 5, 2014
    alexkh
        2
    alexkh  
       May 5, 2014
    @messense 确实是这样。
    官方文档里有解释,对http://www.example.com/myapp/?page=3之类的请求,URLconf 会寻找myapp/。忽略掉参数及其值。

    请见tutorial第三部分,https://docs.djangoproject.com/en/1.6/intro/tutorial03/
    messense
        3
    messense  
       May 5, 2014
    @alexkh 看来我猜的不错,哈哈。cc @larkifly 官方是这样说的:

    Note that these regular expressions do not search GET and POST parameters, or the domain name. For example, in a request to http://www.example.com/myapp/, the URLconf will look for myapp/. In a request to http://www.example.com/myapp/?page=3, the URLconf will also look for myapp/.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2469 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 11:48 · PVG 19:48 · LAX 04:48 · JFK 07:48
    ♥ Do have faith in what you're doing.