Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Flask Basics Templates and Static Files Flat HTML

Problem with the code

I'm following Kenneth and I have the same code but when I reload the page I'm still having the first view, "Hello from Planet Earth" I don't know why it doesn't run the new view with the html code. Here is my code

from flask import Flask

app = Flask(name)

@app.route('/') @app.route('/<name>') def index(name='Planet Earth'): return 'Hello from {}'.format(name)

@app.route('/add/<int:num1>/<int:num2>') @app.route('/add/<float:num1>/<float:num2>') @app.route('/add/<int:num1>/<float:num2>') @app.route('/add/<float:num1>/<int:num2>') def add(num1, num2): return """ <!doctype html> <html> <head><title>Adding!</titel></head> <body> <h1>{} + {} = {}</h1> </body> </html> """.format(num1, num2, num1+num2)

app.run(debug=True, port=8000, host='')

MAybe I know where is the problem, it didn't appear the sum of num1 and num2 because are between the triple quotes, i'm using vs code, and change the color not as happens with kenneth

1 Answer

Alex Koumparos
Alex Koumparos
Python Development Techdegree Student 36,862 Points

Hi Federico,

Please remember to put your code inside the correct markdown tags to prevent it being mangled when converted to HTML (e.g., look at what has happened to the line that should be app = Flask(__name__): it has been changed to app = Flask(name)). This is always important when asking a question about any language, but especially Python where whitespace is significant (unless you properly mark your code block, any quantity of whitespace gets converted to a single space) and in Python double underscores (dunders) are rampant (these get interpreted as bold text when not properly marked).

As for your question, what page are you loading? Are you loading /add/2/5 (the page Kenneth is loading) or just /. I reconstructed your code as best I could from the html and when I ran it I definitely got a different output from /add/2/5 than I get from just /.

However, I did get what looks like a blank page instead of the "2 + 5 = 7" that Kenneth gets. This is because you have a typo in your HTML. You open the <title> tag but then close a (nonexistent) <titel> so the browser thinks the whole page is inside your title tag. Once that typo is fixed, I get exactly the same output as Kenneth.

Hope that helps,



Alex, thanks a lot! I;ve got it! Sometimes it happen to me that I really pay attention and I see the exact code, and now I see that it is not the same as I wrote. So sorry and thank you for your time! I'll check it right know