2
votes

I cannot figure out where the extra None is coming from. I've tried these links to no avail: Build error with variables and url_for in Flask how to use Flask Jinja2 url_for with multiple parameters

Also, I am not using BluePrint.

Here is my users.html template:

<a href="{{ url_for('user_page', user_id=user.user_id) }}"> {{ user.name }} </a>

Here are two different user.py files I've tried:

@app.route('/user')
def user_page():
    args = show_user_parser.parse_args()
    user_id = args['user_id']
    return page_for_user(user_id)

@app.route('/user/<user_id>')
def user_page(user_id):
    return page_for_user(user_id)

def page_for_user(user_id):
   try:
       cur.execute(list_user_detailed_query, (user_id,))
   except psycopg2.OperationalError:
       return render_template('error.html')
   except psycopg2.IntegrityError:
       connection.rollback()
       return render_template('error.html')
   data = cur.fetchone()
   return render_template('user.html',
                          name=data['name'],
                          email=data['email'],
                          undergrad=data['undergrad'],
                          cv=data['cv'])

Here is the build error:

BuildError: ('user_page', {'user_id': '1'}, None)
1
what does this page_for_user() function do ? Can you show the code for it ? - codegeek
added code, although it's probably not relevant since manually entering the /user/id or /user?user_id=... was working just fine. - Todd Anderson

1 Answers

1
votes

You've named both your routes "user_page", so I bet the first one (which takes no arguments) is winning and when you try to construct a url with arguments it fails. Rename the functions so they're different and that should fix it.