add bootstrap designed web form (suppress WTForms)

develop
gwen 2 years ago
parent e382c431c8
commit 3e911f15ec

@ -22,8 +22,8 @@ app = Flask(
app.url_map.strict_slashes = False
app.config.update(dict(
SECRET_KEY= secret_key,
WTF_CSRF_SECRET_KEY= wtf_csrf_secret_key
SECRET_KEY= secret_key
# WTF_CSRF_SECRET_KEY= wtf_csrf_secret_key
))
@app.before_request

@ -21,7 +21,7 @@ Then the 'dynamic' (calculated) routes :
import typing as t
from flask import Blueprint, render_template, request, redirect
from flask import Blueprint, render_template, request, url_for, redirect
import folium
from pymongo import ASCENDING
@ -31,34 +31,22 @@ from .helper import make_timeitem_from_filename
main = Blueprint("main", __name__, url_prefix="/")
# flask wtforms
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField
from wtforms.validators import DataRequired
class SearchForm(FlaskForm):
search = StringField('Recherche', validators=[DataRequired()])
submit = SubmitField(label=('Rechercher'))
# ______________________________________________________________________________
# routes
@main.route("/", methods=('GET', 'POST'))
def home():
"""home route"""
form = SearchForm()
if form.validate_on_submit():
return f'''<h1> Welcome {form.search.data} </h1>'''
return render_template("home.html", form=form)
if request.method == 'POST':
search = request.form['search']
return render_template("form2.html", search=search)
return render_template("home.html")
@main.route("/about/", methods=('GET', 'POST'))
def about():
"""about route"""
form = SearchForm()
if form.validate_on_submit():
return f'''<h1> Welcome {form.search.data} </h1>'''
return render_template("about.html", form=form)
return render_template("about.html")
@main.route("/actes/")

@ -34,9 +34,8 @@
<a class="nav-link" href="{{url_for('main.contact')}}">Contact</a>
</li>
</ul>
<form method="POST" action="" class="form-inline mt-2 mt-md-0">
{{ form.csrf_token }}
<input name="search" class="form-control mr-sm-2" type="text" placeholder="Recherche" aria-label="Search">
<form method="POST" class="form-inline mt-2 mt-md-0">
<input name="search" class="form-control mr-sm-2" type="text" placeholder="Recherche" aria-label="Search" value="{{ request.form['search'] }}">
<button name="submit" class="btn btn-outline-success my-2 my-sm-0" type="submit">Rechercher</button>
</form>
</div>

@ -0,0 +1,43 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
a {
text-decoration: none;
display: inline-block;
padding: 8px 16px;
}
a:hover {
background-color: #ddd;
color: black;
}
.previous {
background-color: #f1f1f1;
color: black;
}
.next {
background-color: #04AA6D;
color: white;
}
.round {
border-radius: 50%;
}
</style>
</head>
<body>
<h2>En travaux</h2>
<p>Résulat du query : {{ search }} </p>
<a onclick="history.back()" class="next">&laquo; Retour</a>
</body>
</html>
Loading…
Cancel
Save