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

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

  •  
  •   y0ung · 2016-06-14 11:31:17 +08:00 · 2650 次点击
    这是一个创建于 2870 天前的主题,其中的信息可能已经有所发展或是发生改变。
    @app.route('/user/<uname1>/friend/<fname>')
    def v_users4(uname1,fname):
    return '<h1>%s\'s friend - %s\'s profile</h1>' % uname1,fname
    4 条回复    2016-06-14 12:05:41 +08:00
    fohnwind
        1
    fohnwind  
       2016-06-14 11:43:13 +08:00   ❤️ 1
    格式化字符串的时候需要%(uname1, fname)这样吧?个人感觉
    不然的话会被 return 识别成另外的返回值,我记得 flask 的 return 第二个值会认为是状态码
    y0ung
        2
    y0ung  
    OP
       2016-06-14 11:45:44 +08:00
    666 谢谢
    cdlnls
        3
    cdlnls  
       2016-06-14 11:47:26 +08:00 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
       2016-06-14 12:05:41 +08:00
    知道了 ,老司机 多多指教
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3538 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 11:12 · PVG 19:12 · LAX 04:12 · JFK 07:12
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.