Python flask - Encoding links based on JSON varibale -


i'm creating application in python flask , i'm struggling encode links. in html template i'm calling data json , based on variable json, want create link page variables have "space" in them, take first word , link doesn't work should.

this json:

[    {       "team":"afc bournemouth"    },    {       "team":"arsenal"    } ] 

and python:

@app.route('/<team>/') def artist(team):     json_data=open('static/data.json').read()     data= json.loads(json_data)     urllib.quote_plus(data.team)     return render_template("team.html", team=team) 

i'm trying use "urllib.quote_plus" error

attributeerror: 'list' object has no attribute 'team'

i don't know how fix it.

and loop in html:

{% data in results %}     <div class="team">         <p><a href=/{{ data.team }}>{{ data.team }}</a></p>     </div> {% endfor %} 

before used "urllib.quote_plus" link "arsenal" worked perfect, "afc bournemouth" took word "afc".

that strange working correctly "arsenal". should iterate on "data" because list

example:

@app.route('/<team>/') def artist(team):     json_data=open('static/data.json').read()     data= json.loads(json_data)     data = [{'team': urllib.quote_plus(team['team'])} team in data]     return render_template("team.html", results=data) 

another thing in render_template sending variable team , not results (changed in example). way should fine , work jinja template.

edit: changed list comprehension


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -