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 trialLa Mac
612 Pointsflask basic
the code isnt rendering "Treehouse" when it runs. it give me unsecured sight mess
from flask import Flask
from flask import request
app = Flask(__name__)
@app.route('/')
def index(name="Treehouse"):
return "Hello from {}".format(name)
app.run(debug=True, port=8000, host='0.0.0.0')
[MOD: added ```python formatting -cf]
La Mac
612 Pointsyes it still errors . when i safe my work and then run this the workspace renders workspace is unavailable
Chris Freeman
Treehouse Moderator 68,454 PointsIf in a workspace, can you use the snapshot feature (button upper right) to create a snapshot and post the link?
8 Answers
Jeff Muday
Treehouse Moderator 28,720 PointsHere is me running the app.
Chris Freeman
Treehouse Moderator 68,454 Points+1 for using Screencast-O-Matic!!
Jeff Muday
Treehouse Moderator 28,720 PointsChris is correct-- the following runs. Make sure to outdent the app run. Python is very picky when it comes to spacing.
The browser will respond on port 8000, you need to pick that from the menu. Also, you have specified name="Treehouse"
as the parameter. You may have wanted dual routes where you can specify the parameter.
Have fun with Flask, you can build some very useful websites!
from flask import Flask
app = Flask(__name__)
@app.route('/<name>') # this is the extra route.
@app.route('/')
def index(name="Treehouse"):
return "Hello from {}".format(name)
app.run(debug=True, port=8000, host='0.0.0.0')
La Mac
612 PointsI put this code in, run program from the prompt port=8000 it returns a page that says "workspace unavailable ,This is a preview link for a Treehouse workspace that is know longer active".
from flask import Flask
app = Flask(_name_)
@app.route('/<name>')
@app.route('/')
def index(name="Treehouse"):
return "Hello from {}".format(name)
ap.run(debug=True, port=8000, host='0.0.0.0')
[MOD: added ```python formatting -cf]
Chris Freeman
Treehouse Moderator 68,454 PointsLa Mac, in your latest code some errors persist:
- you have
ap.run
instead ofapp.run
- the
app.run
line should not be indented - the
Flask(_name_)
should be using dunderFlask(__name__)
When you run python app.py
in the workspace console window, you should see:
treehouse:~/workspace$ python app.py
* Running on http://0.0.0.0:8000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 230-926-566
The launch the preview, being sure to select the 8000
option
The console should display this if the page load was registered by the app:
172.18.40.248 - - [07/May/2021 19:17:34] "GET / HTTP/1.1" 200 -
172.18.40.248 - - [07/May/2021 19:17:35] "GET /favicon.ico HTTP/1.1" 200 -
La Mac
612 Pointswhen i run this in workspace it launches the preview, i choose 8000 option. it comes back with :
Workspace Unavailable This is a preview link for a Treehouse Workspace that is not currently active. If you are the workspace owner, you can launch it again via the Treehouse site.
from flask import Flask
app = Flask(name)
@app.route('<name>') @app.route('/')
def index(name="Treehouse"):
return "Hello from {}".format(name)
app.run(debug=True, port=8000, host='0.0.0.0')
Chris Freeman
Treehouse Moderator 68,454 PointsIt may be that the issue is with a local conflict with port 8000. Can you try using one of the other port numbers, say, 8080?
La Mac
612 Pointswhen i run this in workspace it launches the preview, i choose 8000 option. it comes back with :
Workspace Unavailable This is a preview link for a Treehouse Workspace that is not currently active. If you are the workspace owner, you can launch it again via the Treehouse site.
from flask import Flask
app = Flask(name)
@app.route('<name>') @app.route('/')
def index(name="Treehouse"):
return "Hello from {}".format(name)
app.run(debug=True, port=8000, host='0.0.0.0')
La Mac
612 Pointswhen i did the same coding in the challenges task portion of treehouse i past when i use it in my workspace it doesn't pass
La Mac
612 Pointsbefore i started asking for help i went down the line 3000 , 4567 , 8000 , 8080 , 9292 . All came back as :
Workspace Unavailable This is a preview link for a Treehouse Workspace that is not currently active. If you are the workspace owner, you can launch it again via the Treehouse site.
yet when in task challenge on treehouse my coding came back "good - green" i used another computer too.
Chris Freeman
Treehouse Moderator 68,454 PointsCan you confirm you’re running the app before the connecting to the port number:
treehouse:~/workspace$ python app.py
La Mac
612 Pointsthis is what a code validator says 6 issues
The character encoding was not declared. Proceeding using “windows-1252”.
Non-space characters found without seeing a doctype first. Expected e.g. “<!DOCTYPE html>”. From line 1, column 1 to line 1, column 23 Code Extract: from flask import Flask↩↩app
Element “head” is missing a required instance of child element “title”. From line 1, column 1 to line 1, column 23 Code Extract: from flask import Flask↩↩app
Element “name” not allowed as child of element “body” in this context. (Suppressing further errors from this subtree.) From line 5, column 14 to line 5, column 19 Code Extract: p.route('<name>')↩@a
End of file seen and there were open elements. At line 11, column 46 Code Extract: ='0.0.0.0)
Unclosed element “name”. From line 5, column 14 to line 5, column 19 Code Extract: p.route('<name>')↩@a
La Mac
612 Pointsthis is the workspace url # just before i run to get the launch i choose 8000 . is this answering your question
Chris Freeman
Treehouse Moderator 68,454 PointsGreat! I don’t have permission to see that link. Can you use the “snapshot” creature at that link to create a snapshot and post that link?
Chris Freeman
Treehouse Moderator 68,454 PointsChris Freeman
Treehouse Moderator 68,454 PointsThe
app.run
line appears to be indented. Can you fix and confirm if error persists?