Как получить bootstrap выпадающее значение в flask маршруте - PullRequest
0 голосов
/ 17 февраля 2020

Я хочу получить выбранный элемент из раскрывающегося списка в моей функции маршрута, а затем отправить его другой функции.

Мой html выглядит следующим образом:

<div class="form-group">
  <label class="col-md-4 control-label" >Where do you want to go</label> 
    <div class="col-md-4 inputGroupContainer">
        <div class="dropdown" name = "destination_place" id="destination_place">
        <button class="btn btn-default dropdown-toggle" name = "destination_place" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
        <span id="selected" > Destination Place </span>
        <span class="caret"></span>
        </button>

        <ul class="dropdown-menu" aria-labelledby="dropdownMenu1"  >
        <li><a href="#" name = "destination_place" value = "Coorg">Coorg</a></li>
        <li><a href="#" name = "destination_place" value = "Mysore">Mysore</a></li>
        <li><a href="#" name = "destination_place" value = "Chikmagalur">Chikmagalur</a></li>
        <li><a href="#" name = "destination_place" value = "Hampi">Hampi</a></li>
        <li><a href="#" name = "destination_place" value = "Bangalore">Bangalore</a></li>
        <li><a href="#" name = "destination_place" value = "Udupi">Udupi</a></li>
        <li><a href="#" name = "destination_place" value = "Murudeshwar">Murudeshwar</a></li>

        </ul>
        </div>
    </div>
</div>

и моя Flask функция выглядит следующим образом:

@mod.route('/login/<int:userid>/', methods=['GET', 'POST'])
def mainplace(userid):
    userid = userid
    if request.method == 'POST':
        destination_place = request.form['destination_place']
        return redirect(url_for('itinerary.getMap', destination_place=destination_place))
    return render_template('user.html', userid = userid)

@mod.route('/getMap/<destinationplace>')
def getMap(destination_place):
    print("inside getMap routes",file=sys.stderr)
    dtn, details = itineary(destination_place)
    print(dtn, file=sys.stderr)
    print("Itinerary is " , details, file=sys.stderr)
    return render_template('direction.html', dtn=dtn, details = details)

Я не уверен, где мне дать name = "destination_place" или есть что-то еще, что я могу сделать. Я получаю ошибку, подобную этой

werkzeug.exceptions.HTTPException.wrap.<locals>.newcls: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
At
destination_place = request.form['destination_place']
...