擅长:python、mysql、java
<p>我想你的问题是:</p>
<pre><code>if request.method == 'POST':
return render_template('algo.html')
if request.method == 'POST' and request.form['submit'] == 'swipeleft':
print "yes"
</code></pre>
<p>对于第一个if语句,它将始终返回True,并且函数将返回呈现的模板。它永远不会检查第二个if语句。在</p>
<p>只需切换位置,这样它就可以检查POST请求以及表单是否已提交。在</p>
^{pr2}$
<p>或者</p>
<pre><code>if request.method == 'POST':
if request.form['submit'] == 'swipeleft':
print "yes"
return render_template('algo.html')
</code></pre>
<p>编辑:
你犯了一个严重的错误:</p>
<pre><code><input type = "submit" name = "submit" value = "swipeleft" method=post>
</code></pre>
<p>更改为:</p>
<pre><code><form method="post" action="URL" > # change URL to your view url.
<input type="submit" name="swipeleft" value ="swipeleft">
</form>
</code></pre>
<p>现在在您看来,请执行以下操作:</p>
<pre><code>if request.method == 'POST' and request.form['swipeleft']:
</code></pre>