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

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

  •  
  •   chaleaoch · 2016-06-06 20:32:51 +08:00 · 1998 次点击
    这是一个创建于 2906 天前的主题,其中的信息可能已经有所发展或是发生改变。
    举例:
    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 条回复    2016-06-06 21:34:32 +08:00
    jimmyye
        1
    jimmyye  
       2016-06-06 21:34:32 +08:00   ❤️ 1
    这是一个 wontfix : https://code.djangoproject.com/ticket/15718
    所以你要根据实际情况做特殊处理,比如第一个参数会不会出现"%2F"之类的。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3384 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 10:27 · PVG 18:27 · LAX 03:27 · JFK 06:27
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.