从列表框中获取的任何值都返回为瓶中的"none"值



我有一个网站,您可以在其中获取从网站输入的值(使用bottle(,并将它们添加到数据库中(使用sqlalchemy(。为";状态";需要非常特定的字符串,否则它会失败,所以我考虑使用Listbox来避免错过输入。当调试时,每当我尝试使用任何类型的Listbox时,结果总是返回";none";我该怎么解决这个问题?

相关代码:

@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)

发布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>

像下面这样的其他输入的HTML确实有效。上面的HTML似乎不需要任何输入:

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

您将name放错了位置-它必须在<select>

<select name="Status">
<option selected>Open this select menu</option>
<option>Onloan</option>
<option>Available</option>
</select>

最新更新