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

Steven Young
Steven Young
2,486 Points

html 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'

Steven Young
Steven Young
2,486 Points

here's the index.html file contents:

<!DOCTYPE html> <html> <head></head>

<body class = 'body'>
    <body>
        <h3>{{ title }}</h3>
        <p>{{ paragraph }}</p>
    </body>

</body>

</html>

I have html tags but they aren't showing up here

2 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Just 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 like app = Flask(__name__)
Steven Young
Steven Young
2,486 Points

yes to all three i just chose the most relevant part of the code to show here

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

OK, so let's try some more stuff :)

Is your app running in debug mode? app.debug = True or app.run(debug=True)

Steven Young
Steven Young
2,486 Points

it 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
Steven Young
2,486 Points

I'm using pythonanywhere BTW if that makes a difference...

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

OK, so, what's in the site and error logs?

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

I 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?