0

I doing a flask app and when i try to put a link to redirect a user to his profile page by calling

BuildError: Could not build url for endpoint 'profile'. Did you forget to specify values ['business_name']?

when i try to login a user.My app works fine the previous days with this same code i do not what has happen and i have tried all possible means to get this right but no way

@app.route('/profile/<business_name>')
@login_required
def profile(business_name):
    user = User.query.filter_by(business_name=business_name).first()
    if user == None:
        flash('This Profile does not exist {}'.format(business_name))
        return redirect(url_for('login'))

    return render_template('profile.html',user=user)

(main.html)

<ul class="nav navbar-nav">
    <li><a href="{{ url_for('home_page') }}" class="active">Home</a></li>
    {% if g.user.is_authenticated %}
    <li><a href="{{ url_for('profile', business_name=g.user.business_name) }}">Your Profile</a></li>
    <li><a href="{{url_for('logout')}}">Logout</a></li>
Nabin
  • 11,216
  • 8
  • 63
  • 98
  • 1
    The error seems to indicate the `business_name` is not defined and is coming in as `null`, perhaps. Are you sure your user is logged in (and is not anonymous) and that `business_name` is an object? – Carlos Aug 20 '17 at 23:04
  • May help: https://stackoverflow.com/questions/30501522/werkzeug-routing-builderror-with-flask-python?rq=1 – whackamadoodle3000 Aug 20 '17 at 23:43

1 Answers1

1

Problem is you are not defining the route view function to take in the following form:

/profile/business_name

Hence you should send business_name in URL but you are sending arguments to the function. You should do the following:

<a href="/profile/{{business_name=g.user.business_name }}">
Nabin
  • 11,216
  • 8
  • 63
  • 98