Skip to content
Advertisement

Any values taken from a Listbox return as “none” in bottle

I have a website in which you take values inputted from a website (using bottle) and add them to a database (using sqlalchemy). The data gathered for “Status” needs very specific strings otherwise it will fail so I thought of using a Listbox in order to avoid a miss input. When debugging whenever I try to use any type of Listbox however the result always returns “none” How can I fix this?

Relevant code:

@route('/savenew', method='post')
def savenew():
    pass
    # Gathers all of the information from the html inputs
    add_Assetid = request.forms.get('Assetid')
    add_AssetName = request.forms.get('AssetName')
    add_category = request.forms.get('Category')
    add_borrower = request.forms.get('Borrower')
    add_status = request.forms.get('Status')
    add_value = request.forms.get('Value')

    # open a session
    db_engine = create_engine('sqlite:///db/MusicAssets.db')
    # creates a sessionmaker class for dynamic class creation
    Session = sessionmaker(bind=db_engine)
    # object creation
    session = Session()
    try:
        # this adds all the new varibles inputted to the database
        new_music = Music(
            Assetid=add_Assetid,
            AssetName=add_AssetName,
            Category=add_category,
            Borrower=add_borrower,
            Status=add_status,
            Value=add_value
        )
        session.add(new_music)
        # commits to the changes being made.
        session.commit()
        # lets user use the changes were made and successful
        message = "Successfully added entry"

    # Error handling code any error stops ALL changes
    except Exception as e:
        # error message trying to give guidence to what could be the problem
        error = ("Please make sure you have used correct values e.g only "
                 "using numbers for Value or inputting status correctly, "
                 "Onloan and Avaliable are the only accepted inputs "
                 "and are cap sensitive")
        message = f"Error adding entry: " + error
    finally:
            # Goes to messgae template to display if the changes were sucessful
            return template('changemsg.tpl', message=message)

Relevent HTML:

            <div class="form-group">
                <label for="exampleInputPassword1">Status</label>
                <select class="form-select form-select-sm" aria-label=".form-select-sm example">
                    <option selected>Open this select menu</option>
                    <option name="Status">Onloan</option>
                    <option name="Status">Available</option>
                </select>
            </div>

This HTML for other inputs like this one below does work. It’s just HTML above that doesn’t seem to take any inputs:

            <div class="form-group">
                <label for="exampleInputPassword1">Value</label>
                <input type="number" name="Value" class="form-control" />
            </div>

Advertisement

Answer

You have name in wrong place – it has to be in <select>

<select name="Status">
    <option selected>Open this select menu</option>
    <option>Onloan</option>
    <option>Available</option>
</select>
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement