我正在使用Flask,HTML,CSS,Jinja&我的任务的SQL。我需要帮助从HTML / Jinja中检索值,以便在我的SQL查询中使用它们(在python中)我希望代码可以帮助你更好地理解..
HTML /金贾
<section id="filters">
<select id="Genre" name="genres" onchange="window.location.reload(true)">
{% for row in genre %}
<option value="{{row.genre}}">{{row.genre}}</option>
{% endfor %}
</select>
</section>
的Python /瓶
@app.route('/')
def homepage():
db = get_db()
select = request.form.getlist('genres')
general = db.execute (
"""
SELECT Movies.Movie_ID, Movies.Name, Movies.Rating_IMDB,
Movies.Rating_RT
FROM Movie_Genre
JOIN Movies ON Movie_Genre.Movie_ID = Movies.Movie_ID
JOIN Genres ON Movie_Genre.Genre_ID = Genres.Genre_ID
WHERE Genres.Genre = ?;
""",
(str(select),)
)
genres = db.execute("SELECT Genre FROM Genres")
basic = general.fetchall()
genre = genres.fetchall()
return render_template('index.html', basic=basic, genre=genre)