Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMUZ140716 Taurayi Kwenda
2,781 PointsFlash Basics Challenge Task 3 of 3
Where is the problem? If l put
return render_template("hello.html", {{name}}=”name”)
At the end TASK ONE IS NO LONGER PASSING
Please assist
from flask import Flask
from flask import render_template
app = Flask(__name__)
@app.route('/hello/<name>')
def hello(name="Treehouse"):
return render_template("hello.html", name='name')
<!doctype html>
<html>
<head><title>Hello!</title></head>
<body>
<h1>Howdy!</h1>
</body>
</html>
3 Answers
Chris Freeman
Treehouse Moderator 68,457 PointsHere is your whole code with corrections:
flask_app.py
from flask import Flask
from flask import render_template
app = Flask(__name__)
@app.route('/hello/<name>')
def hello(name="Treehouse"):
return render_template("hello.html", name=name) #<-- removed quotes from name
templates/hello.html
<!doctype html>
<html>
<head><title>Hello!</title></head>
<body>
<h1>Howdy! {{ name }}</h1> {# added name #}
</body>
</html>
Sage Elliott
30,003 PointsYou need to assign the variable name, so you do not need those quotations around the name = 'name'. Should look like this:
flask_app.py
return render_template("hello.html", name=name)
Inside your template file pass the name variable next to "howdy!". In flask you use double curly brackets{{}} to print the variables value.
templates/hello.html
<h1>Howdy! {{ name }} </h1>
I hope this helps! :)
MUZ140716 Taurayi Kwenda
2,781 PointsThanx it is still giving me problems kindly revise my whole code the TASK is "Pass the name argument to the template. Print the name variable in the <h1> in the template."
Sage Elliott
30,003 PointsWoops my second code snippet was messed up! In you template add {{ name }} after howdy in the h1 tags
Sage Elliott
30,003 PointsI fixed in original post:
<h1>Howdy! {{ name }} </h1>
Seth Reece
32,867 PointsIn flask_app.py change name='name'
to name = name
. In hello.html put {{ name }}
After Howdy!
MUZ140716 Taurayi Kwenda
2,781 PointsThanx it is still giving me problems kindly revise my whole code and write it below. The TASK is "Pass the name argument to the template. Print the name variable in the in the template."