<p>在<code>?</code>之后需要<code>route('/longword/')</code>无参数</p>
<p>然后可以在<code>?</code>之后使用参数运行</p>
<pre><code>http://localhost:5000/longword/?gameid=123&playerid=456
</code></pre>
<p>在函数中,您可以使用<code>request.args.get()</code>获取这个参数</p>
<pre><code>@app.route('/longword/')
def longword():
gid = request.args.get('gameid')
pid = request.args.get('playerid')
return "GID: %s PID: %s" % (gid, pid)
</code></pre>
<p>最后一件事:即使发送数字,参数也是字符串,因此需要<code>%s</code>,而不是<code>%d</code></p>
<hr/>
<p>顺便说一句:你可以运行这个网址也没有一些参数即</p>
<pre><code>http://localhost:5000/longword/?gameid=123
http://localhost:5000/longword/?playerid=456
http://localhost:5000/longword/
</code></pre>
<p>你可以用<code>request.args.get()</code>设置默认值</p>
<pre><code> gid = request.args.get('gameid', 'default gameid')
pid = request.args.get('playerid', 'default playerid')
</code></pre>
<p>如果不使用自己的默认值,则<code>request.args.get()</code>将使用<code>None</code></p>
<pre><code> gid = request.args.get('gameid')
pid = request.args.get('playerid')
if not gid or not pid:
return "You forgot gameid or playerid"
return "GID: %s PID: %s" % (gid, pid)
</code></pre>