why does function url_for() in Flask produced this error?
<p>When I use flask, in my first template(a.html) I wrote:</p>

<pre><code>{{url_for('auth.confirm', token=token, _external=True)}}
</code></pre>

<p>It gave the right site: <code>/auth/confirm/&lt;token&gt;</code></p>

<p>But in another:<code>{{url_for('auth.forget', token=token, _external=True)}}</code></p>

<p>It gave me a site like this: <code>/auth/forget?token=&lt;token&gt;</code></p>

<p>What makes the diffence?<br /></p>

<p>Codes here:</p>

<pre><code>@auth.route('/forget', methods=['GET', 'POST'])
def forget():
form=ForgetPasswordForm()
if form.validate_on_submit():
    user=User.query.filter_by(email=form.email.data).first()
    if user:
        token=user.generate_forget_token()
        send_email(user.email, 'Reset your password',   'auth/email/forget', token=token)
        return redirect(url_for('main.index'))
    flash("Email is not exist")
return render_template('auth/forget.html',form=form)

@auth.route('/forget/&lt;token&gt;', methods=['GET', 'POST'])
def forget_reset(token):
try:
    email=User.confirm_forget(token)
except:
    return render_template('404.html')
form=PasswordOnlyForm()
if form.validate_on_submit():
    user=User.query.filter_by(email=email).first()
    user.password=form.password.data
    db.session.add(user)
    db.session.commit()
    flash('Succeed, now login!')
    return redirect('auth/login')
return render_template('auth/PasswordOnly.html',form=form)
</code></pre>

<p>The underlying functions are expecting different urls.</p>

<p>In the first case, the flask routing decorator looks like:</p>

<pre><code>@app.route('/auth/confirm/&lt;token&gt;')
def confirm(token):
</code></pre>

<p>In the second, the token is not specified, and therefore passed as a query parameter.</p>

<pre><code>@app.route('/auth/forget/')
def forget():
</code></pre>

<p>You'll also need to be careful about which function you are calling. In your example above, you have two functions: <code>forget</code> and <code>forget_reset</code> which have two different behaviors.</p>

<pre><code>@app.route('/auth/forget/')
def forget():
    pass

@auth.route('/forget/&lt;token&gt;', methods=['GET', 'POST'])
def forget_reset(token):
    pass
</code></pre>

<p>Now you call them slightly differently. If you call forget:</p>

<pre><code>&lt;a href="{{url_for('forget', token='hello')}}"&gt;Calling Forget&lt;/a&gt;

http://127.0.0.1:5000/forget?token=hello
</code></pre>

<p>And if you call forget_reset:</p>

<pre><code>&lt;a href="{{url_for('forget_reset', token='hello')}}"&gt;Calling Forget Reset&lt;/a&gt;

http://127.0.0.1:5000/forget/hello
</code></pre>

python web flask