Python Forum

Full Version: Problem with arguments in route function.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I need to have two arguments in my search_results2 function but it keeps saying missing 1 required positional argument. I have no idea what to do with it i have two in there but it still saying one is missing. Could anyone help me with this?

Error:
TypeError: search_results2() missing 1 required positional argument: 'search2'
@app.route('/results2')
def search_results2(username, search2):
    
    results = []
    search_string = search2.data['search2']

    if search_string:
        if search2.data['select'] == 'Enummer':
            qry = db_session.query(Matrial, Enummer).filter(
                Enummer.id==Matrial.Enummer_id).filter(
                    Enummer.name.contains(search_string))
            results = [item[0] for item in qry.all()]
        elif search2.data['select'] == 'Varumärke':
            qry = db_session.query(Matrial).filter(
                Matrial.varumarke.contains(search_string))
            results = qry.all()
        elif search2.data['select'] == 'Produkt':
            qry = db_session.query(Matrial).filter(
                Matrial.produkt.contains(search_string))
            results = qry.all()
        else:
            qry = db_session.query(Matrial)
            results = qry.all()
    else:
        qry = db_session.query(Matrial)
        results = qry.all()

    if not results:
        flash('No results found!')
        return redirect(url_for("user_home", username=username))
    else:
        # display results
        table = Results2(results)
        table.border = True
        return render_template('results.html', table=tabl, username=username)
please show entire, unmodified error traceback
also enough code to support failing module
@app.route has a connection with function under.
Can not take in 1 value from route and have 2 argument in function.
Just to make it clear route is the url in address bar.
@app.route('/user/<user_name>')
def foo(user_name):
    user_name = user_name.capitalize()    
    return render_template('user.html', name=user_name)
Call this would be http://127.0.0.1:5000/user/kent

def foo(user_name, arg): would give your error.
Error:
TypeError: foo() missing 1 required positional argument: 'arg'
There are way to get several parameter from route or maybe you mean to get values from the web-site eg html form.
It more normal/better to keep route(url call) rather simple,if need many argumet do this in web-site.

Look here for some examples multiple parameters in route.