I would like to pass a parameter to a Flask app from a Jinja2 template that contains white space. In the example below I am trying to pass Dallas Cowboys.
template
{% set homeTeam = 'Dallas Cowboys'%}
{% set league = 'nfl' %}
{% set sport = 'football' %}
{% set url = '/details/' + sport + '/' + league + '/' + homeTeam %}
<a href={{url}}>{{time_formatted}} - {{homeTeam}} vs. {{awayTeam}}</a>
<a href={{url}}>Click Me</a>
What I want here is:
<a href="/details/football/nfl/dallas%20cowboys>Click Me</a>
What I get is:
<a href="/details/football/nfl/dallas" cowboys?="">Click Me</a>
I want to be able to print "Dallas Cowboys" in the Flask function below:
app
@app.route('/details/<sport>/<league>/<home_team>')
def details(sport, league, home_team):
print(sport, league, home_team) #I need "Dallas Cowbows" for home_team
return render_template('details.html', sport=sport, league=league, home_team=home_team)
question from:
https://stackoverflow.com/questions/65920086/how-do-i-pass-a-url-from-a-jinja2-template-to-a-flask-app-route-function-whea 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…