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 Welcome to Flask Request args

'/' gave a none 200 response

why is it, that my code gave a "none 200 response", even if I copied Kenneth's code, except the server starting (app.run(...) ), what as far as I understand isn't necessary.

flask_app.py
from flask import Flask
from flask import request
app = Flask(__name__)

@app.route("/index")
def index(name = "Hodor"):
    name = request.arg.get("name", name)
    return "Hello {name}".format(name)

1 Answer

Ok, first of all, thank you for your Answer!

I found my mistake: its a misunderstanding of the .format()-methode right after the return in quotes stands "Hello {name}".format(name) that is wrong. The right solution to that Problem is leaving the curlys empty: "Hello {}".format(name)

thanks for your Time =)

Michael Hulet
Michael Hulet
47,843 Points

Wow, I totally overlooked that. Sorry about that! I missed that because Python 3.6 (the current latest version, and the one that's been my daily driver for a few months now) and later have "f strings". Python will evaluate whatever expression you want inside those brackets, so your statement would be perfectly valid without the call to format. In fact, if you're using Python 3.6 on your machine (which you should be), you should try it out!:

return f"Hello {name}" # This is the entire statement in 3.6