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

在 flask 匹配动态 URL 中,我这样的写法对吗?求帮助

  •  
  •   y0ung · Jun 14, 2016 · 3561 views
    This topic created in 3612 days ago, the information mentioned may be changed or developed.
    @app.route('/user/<uname1>/friend/<fname>')
    def v_users4(uname1,fname):
    return '<h1>%s\'s friend - %s\'s profile</h1>' % uname1,fname
    4 replies    2016-06-14 12:05:41 +08:00
    fohnwind
        1
    fohnwind  
       Jun 14, 2016   ❤️ 1
    格式化字符串的时候需要%(uname1, fname)这样吧?个人感觉
    不然的话会被 return 识别成另外的返回值,我记得 flask 的 return 第二个值会认为是状态码
    y0ung
        2
    y0ung  
    OP
       Jun 14, 2016
    666 谢谢
    cctv6
        3
    cctv6  
       Jun 14, 2016 via Android   ❤️ 1
    如果不用括号应该会报错
    >>> print '%s to %s' %'a','b'
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    TypeError: not enough arguments for format string
    >>> print '%s to %s' %('a','b')
    a to b
    y0ung
        4
    y0ung  
    OP
       Jun 14, 2016
    知道了 ,老司机 多多指教
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5130 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 01:14 · PVG 09:14 · LAX 18:14 · JFK 21:14
    ♥ Do have faith in what you're doing.