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 trialSteven Young
2,486 Pointshtml render_template not working
here's the code:
@app.route('/sentdex') def sentdex(): return render_template ("index.html", title = "hi", paragraph = "the para")
I'm using pythonanywhere.com. I have two variables in my index.html page, title and paragraph
the message I'm getting is 'internal server error'
2 Answers
Kenneth Love
Treehouse Guest TeacherJust a bit of sanity check:
- You have
render_template
imported? - Your index.html template is in the
templates/
directory? - You created a Flask app named
app
? Usually you do this with something likeapp = Flask(__name__)
Steven Young
2,486 Pointsyes to all three i just chose the most relevant part of the code to show here
Kenneth Love
Treehouse Guest TeacherOK, so let's try some more stuff :)
Is your app running in debug mode? app.debug = True
or app.run(debug=True)
Steven Young
2,486 Pointsit wasn't, I added it to the end of the app and the error message changed, now it says:
"Something went wrong :-(
This website is hosted by PythonAnywhere, an online hosting environment. Something went wrong while trying to load it; please try again later.
If this is your PythonAnywhere-hosted site, there may be a bug in your code. Check your site's server and error logs for any messages — you can view them from the Web tab inside PythonAnywhere.
You'll find a series of tips on how to debug problems, and solutions to common issues on our Help pages
If you get completely stuck, then drop us a line at support@pythonanywhere.com, in the forums, or using the "Send feedback" link on the site, quoting the error code below.
Error code: Unhandled Exception"
Steven Young
2,486 PointsI'm using pythonanywhere BTW if that makes a difference...
Kenneth Love
Treehouse Guest TeacherOK, so, what's in the site and error logs?
Steven Young
2,486 Pointshow do i check that
Kenneth Love
Treehouse Guest TeacherI don't know much about PythonAnywhere. Surely they have some server/error logs available if they suggest you check them. If not, maybe start here for turning on logging for your app?
Steven Young
2,486 PointsSteven Young
2,486 Pointshere's the index.html file contents:
<!DOCTYPE html> <html> <head></head>
</html>
I have html tags but they aren't showing up here