IscanderCheApril 30, 2024, 4:22 a.m.
Во Flask рендер шаблона не передаётся в браузер
Доброе утро!
Имеется вот такой шаблон:
<!doctype html> <html> <head> <title>{{ title }}</title> <link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap-5.3.2/css/bootstrap.min.css') }}"> <script src="{{ url_for('static', filename='css/bootstrap-5.3.2/js/bootstrap.bundle.min.js') }}"></script> <script src="{{ url_for('static', filename='js/script.js') }}"></script> </head> <body> <p>Tag: {{ tag }}, Button: {{ button }}</p> <form id="tag_form" method="POST"> <label for="text">Tag</label> <input id="text" name="text" size="20" type="text" value=""> <button id="btn" type="button" class="btn btn-outline-secondary btn-sm" data-bs-toggle="button">Personal</button> <input id="submit" name="submit" type="submit" value="Add tag"> </form> </body> </html>
JS-скрипт прикрепляет к POST-запросу дополнительные данные:
document.addEventListener('DOMContentLoaded', (event) => { form = document.getElementById('tag_form'); function readButton(event) { event.preventDefault(); const formSent = new FormData(form); const xhr = new XMLHttpRequest(); const button = document.getElementById('btn').getAttribute('aria-pressed') formSent.append('button', button); xhr.open('POST', 'http://127.0.0.1:5000'); xhr.send(formSent); return false; } form.addEventListener('submit', readButton); });
Python-обработчик эти данные корректно принимает:
from flask import Flask from flask import render_template, request app = Flask(__name__) @app.route('/', methods=['GET', 'POST']) def print_form_data(): if request.method == 'POST': tag = request.form.get('text') button = request.form.get('button') return render_template('index.html', title='Add tag', tag=tag, button=button) # эта строка шаблон с полученными данными не выводит return render_template('index.html', title='Add tag') # эта строка выводит шаблон
В консоли браузера ответ получается корректно, а на самой страничке ничего не показывается. Почему?
We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.Do you like it? Share on social networks!
- Дмитрий
- May 7, 2024, 9:40 a.m.
C ++ - Test 004. Pointers, Arrays and Loops
- Result:60points,
- Rating points-1
d
- dsfs
- April 26, 2024, 4:56 a.m.
C ++ - Test 004. Pointers, Arrays and Loops
- Result:80points,
- Rating points4
Last comments
Qt Linux - Lesson 001. Autorun Qt application under Linux как сделать автозапуск для флэтпака, который не даёт создавать файлы в ~/.config - вот это вопрос ))
АК
Qt WinAPI - Lesson 007. Working with ICMP Ping in Qt Без строки #include <QRegularExpressionValidator> в заголовочном файле не работает валидатор.
Анатолий КононенкоFeb. 5, 2024, 1:50 a.m.
EVADec. 25, 2023, 10:30 a.m.
Boost - static linking in CMake project under Windows Сделал всё по-как у вас, но выдаёт ошибку [build] LINK : fatal error LNK1104: не удается открыть файл "libboost_locale-vc142-mt-gd-x64-1_74.lib" Хоть убей, не могу понять в чём дел…
Qt/C++ - Lesson 056. Connecting the Boost library in Qt for MinGW and MSVC compilers Для решения твой проблемы добавь в файл .pro строчку "LIBS += -lws2_32" она решит проблему , лично мне помогло.
Now discuss on the forum
добавить qlineseries в функции в функции: "GPlotter::addSeries(QString title, QVector &arr)" я вызываю метод setChart(...), я в конструктор передал адрес на QChartView элемент
BlinCTMay 5, 2024, 5:46 a.m.
Best Indian Food Restaurant In Cincinnati OH Ready to embark on a gastronomic journey like no other? Join us at App india restaurant and discover why we're renowned as the Best Indian Food Restaurant In Cincinnati OH . Whether y…
Evgenii LegotckoiMay 2, 2024, 2:07 p.m.
IscanderCheApril 30, 2024, 4:22 a.m.