2

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)
davidism
  • 121,510
  • 29
  • 395
  • 339
Todd Anderson
  • 1,138
  • 9
  • 21

1 Answers1

1

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.

Rachel Sanders
  • 5,734
  • 1
  • 27
  • 36
  • I showed both code snippets, but both are not actually registered simultaneously. I would comment out one def user_page: when running my server. – Todd Anderson May 15 '14 at 17:07