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

2016-06-14 11:31:17 +08:00
 y0ung
@app.route('/user/<uname1>/friend/<fname>')
def v_users4(uname1,fname):
return '<h1>%s\'s friend - %s\'s profile</h1>' % uname1,fname
2659 次点击
所在节点    Python
4 条回复
fohnwind
2016-06-14 11:43:13 +08:00
格式化字符串的时候需要%(uname1, fname)这样吧?个人感觉
不然的话会被 return 识别成另外的返回值,我记得 flask 的 return 第二个值会认为是状态码
y0ung
2016-06-14 11:45:44 +08:00
666 谢谢
cdlnls
2016-06-14 11:47:26 +08:00
如果不用括号应该会报错
>>> 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
2016-06-14 12:05:41 +08:00
知道了 ,老司机 多多指教

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/285575

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX