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 trial

Python Flask Basics Templates and Static Files Simple Template

Ollie Webster
Ollie Webster
5,035 Points

Cannot render template.

I have tried combinations of adding/removing the @app.route('/'), and also adding and removing return` in front ofrender_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__)

def hello(name="Treehouse"):
    return 'Hello {}'.format(name)
    return render_template("hello.html")
<!doctype html>

1 Answer

You 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
Ollie Webster
5,035 Points

Thanks! 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 to hello.html and deal with this in hello(), I'm sure I would have automatically removed the offending code.