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 trialOllie Webster
5,035 PointsCannot render template.
I have tried combinations of adding/removing the @app.route('/')
, and also adding and removing return` in front of
render_template```
The Code Challenge still says that it didn't get the template.
from flask import Flask
from flask import render_template
app = Flask(__name__)
@app.route('/hello/<name>')
@app.route('/')
def hello(name="Treehouse"):
return 'Hello {}'.format(name)
return render_template("hello.html")
<!doctype html>
<html>
<head><title>Hello!</title></head>
<body>
<h1>Howdy!</h1>
</body>
</html>
1 Answer
Alexander Davison
65,469 PointsYou only need to return render_template("hello.html")
. You are returning 'Hello {}'.format(name)
before it, and when you return anything from a function, the function terminates. Thus you only return 'Hello {}'.format(name)
, and not the template.
Ollie Webster
5,035 PointsOllie Webster
5,035 PointsThanks! I just worked this out. To me this seems as an example of the Challenge trying to break up an overall goal into steps that are too small and therefore difficult to put into context of what is trying to be achieved. For example, if they just removed this second part of the challenge and skipped to the third part where it wanted you to pass
name
tohello.html
and deal with this inhello()
, I'm sure I would have automatically removed the offending code.