[Python] Flask. add() takes from 2 to 3 positional arguments but 4 were given

Discussão em 'Python' iniciado por Stack, Junho 10, 2025.

  1. Stack

    Stack Membro Participativo

    I'm a student making a simple wishlist website with user entered data through Flask and SQLalchemy. I've been struggling with this issue and many others ever since I added some new columns to my database. The user inputs the fields through an HTML form, the code of that can be found below.

    <form action="{{url_for('add')}}" method='POST'>
    <input type="text" name="content" id="content">
    <input type="text" name="link" id="link">
    <input type="text" name="price" id="price">
    <input type="submit" value="Add Item"> <!--EndBlock Body-->

    </form>



    When the user presses the submit button it runs the below code to add the user inputted feilds into my database, Content, price and link. but whatever I do it doesn't commit to my database and when it nearly does, it simply throws all of the user inputs into the content column in my database then throws an error (which is probably caused by my attempted workarounds of this problem)

    def add():
    if request.method == 'POST':
    item_content = request.form['content']
    item_price = request.form['price']
    item_link = request.form['link']

    try: #Try to add new item and if fail return error message
    db.session.add(item_content, item_price, item_link) #add the column/row in db
    db.session.commit() #commit item to datebase
    return redirect('/index') #go back to main page
    except:
    return 'There was an Issue adding this item'```

    Many Thanks!

    Continue reading...

Compartilhe esta Página