Flask KeyError или возврат НетPython

Программы на Python
Гость
Flask KeyError или возврат Нет

Сообщение Гость »

Я новичок в изучении веб-разработки Python flask. В настоящее время я переношу свою программу в веб-пространство, но столкнулся с проблемой.
Моя проблема в том, что при нажатии на кнопку «Проверить цену» кнопка должна исчезнуть, получить введите значение поля и появится блок счетчика, который показан в блоке js-скрипта. Однако если нажать на кнопку, появится ошибка о том, что «поле пользовательского ввода» не найдено, хотя ссылка есть и в форме, и в поле ввода. Если добавить в форму id='user-input-field', то запуск выполняется, но js-блок не работает (блок spinner не отображается), а из поля ввода возвращается None, что логично. Если вы измените идентификатор формы, снова произойдет KeyError. В чем может быть проблема?
Мой HTML:


{% extends 'base.html' %}

{% block content %}





Title

{% with messages = get_flashed_messages() %}
{% if messages %}
  • {% for message in messages %}
  • {{ message }}
    {% endfor %}
{% endif %}
{% endwith %}


Product name:


{% if button %}

Check price

{% endif %}


Searching, please wait ...









const hideFunction = () => {
const textInputField = document.getElementById('user-input-field');
const buttonContainer = document.getElementById('button_container');
const spinnerContainer = document.getElementById('spinner-block');
console.log(textInputField);

if (textInputField.value.trim() !== '') {
buttonContainer.style.display = 'none';
spinnerContainer.style.display = 'block';
textInputField.disabled = true;
} else {
buttonContainer.style.display = 'block';
spinnerContainer.style.display = 'none';
}
}



{% endblock %}



и py-файл:
app = Flask(__name__)

@app.route('/competitive_list', methods=["GET", "POST"])
def competitive_list():
if request.method == 'POST':
user_input_name = request.form.get('user-input-field')
print(user_input_name)
time.sleep(2)
return render_template('competitive_list.html',
sample=d,
table=True,
button=True
)
else:
return render_template('competitive_list.html',
button=True
)


Источник: https://stackoverflow.com/questions/781 ... eturn-none

Вернуться в «Python»