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

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

  •  
  •   larkifly · 2014-05-05 17:11:04 +08:00 · 2319 次点击
    这是一个创建于 3637 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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 条回复    2014-05-05 18:11:28 +08:00
    messense
        1
    messense  
       2014-05-05 17:41:00 +08:00
    alexkh
        2
    alexkh  
       2014-05-05 18:02:40 +08:00
    @messense 确实是这样。
    官方文档里有解释,对http://www.example.com/myapp/?page=3之类的请求,URLconf 会寻找myapp/。忽略掉参数及其值。

    请见tutorial第三部分,https://docs.djangoproject.com/en/1.6/intro/tutorial03/
    messense
        3
    messense  
       2014-05-05 18:11:28 +08:00
    @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/.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1017 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 19:02 · PVG 03:02 · LAX 12:02 · JFK 15:02
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.