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

django 的 url 中出现%2F(/),出现捕获异常。如何处理?

  •  
  •   chaleaoch · Jun 6, 2016 · 2512 views
    This topic created in 3688 days ago, the information mentioned may be changed or developed.
    举例:
    url(r'^(.*)/(.*)/$', function)

    def function(request,a,b,c=0):
    return HttpResponse('{}aa{}'.format(a,b))


    测试如下:
    http://10.239.148.113:8000/1/2/
    1aa2
    http://10.239.148.113:8000/1/3%2F2/
    1/3aa2
    django 将%2F 做了 decode 处理之后转给 url partten 。
    由于使用了贪婪模式, 1/3 变成第一个参数,但实际上我想要的第一个参数是 1 ,第二个参数是 3/2

    如何解决这个问题,除了?key=value 这种方式?

    谢谢
    1 replies    2016-06-06 21:34:32 +08:00
    jimmyye
        1
    jimmyye  
       Jun 6, 2016   ❤️ 1
    这是一个 wontfix : https://code.djangoproject.com/ticket/15718
    所以你要根据实际情况做特殊处理,比如第一个参数会不会出现"%2F"之类的。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1084 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 23:24 · PVG 07:24 · LAX 16:24 · JFK 19:24
    ♥ Do have faith in what you're doing.