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:
JavaScript
x
45
45
1
@route('/savenew', method='post')
2
def savenew():
3
pass
4
# Gathers all of the information from the html inputs
5
add_Assetid = request.forms.get('Assetid')
6
add_AssetName = request.forms.get('AssetName')
7
add_category = request.forms.get('Category')
8
add_borrower = request.forms.get('Borrower')
9
add_status = request.forms.get('Status')
10
add_value = request.forms.get('Value')
11
12
# open a session
13
db_engine = create_engine('sqlite:///db/MusicAssets.db')
14
# creates a sessionmaker class for dynamic class creation
15
Session = sessionmaker(bind=db_engine)
16
# object creation
17
session = Session()
18
try:
19
# this adds all the new varibles inputted to the database
20
new_music = Music(
21
Assetid=add_Assetid,
22
AssetName=add_AssetName,
23
Category=add_category,
24
Borrower=add_borrower,
25
Status=add_status,
26
Value=add_value
27
)
28
session.add(new_music)
29
# commits to the changes being made.
30
session.commit()
31
# lets user use the changes were made and successful
32
message = "Successfully added entry"
33
34
# Error handling code any error stops ALL changes
35
except Exception as e:
36
# error message trying to give guidence to what could be the problem
37
error = ("Please make sure you have used correct values e.g only "
38
"using numbers for Value or inputting status correctly, "
39
"Onloan and Avaliable are the only accepted inputs "
40
"and are cap sensitive")
41
message = f"Error adding entry: " + error
42
finally:
43
# Goes to messgae template to display if the changes were sucessful
44
return template('changemsg.tpl', message=message)
45
Relevent HTML:
JavaScript
1
9
1
<div class="form-group">
2
<label for="exampleInputPassword1">Status</label>
3
<select class="form-select form-select-sm" aria-label=".form-select-sm example">
4
<option selected>Open this select menu</option>
5
<option name="Status">Onloan</option>
6
<option name="Status">Available</option>
7
</select>
8
</div>
9
This HTML for other inputs like this one below does work. It’s just HTML above that doesn’t seem to take any inputs:
JavaScript
1
5
1
<div class="form-group">
2
<label for="exampleInputPassword1">Value</label>
3
<input type="number" name="Value" class="form-control" />
4
</div>
5
Advertisement
Answer
You have name
in wrong place – it has to be in <select>
JavaScript
1
6
1
<select name="Status">
2
<option selected>Open this select menu</option>
3
<option>Onloan</option>
4
<option>Available</option>
5
</select>
6