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 trialScript Code
6,631 Pointsjinja2.exceptions.UndefinedError: 'saves' is undefined
app.py
@app.route('/')
def index():
data = {'user_name': 'JohnDoe'}
return render_template("index.html", saves=data)
*index.html*
<input placeholder="Type in Your name" type = "text" id= "name" name = "user_name" value = "{{saves.get('user_name', '') }}" autofocus>
JohnDoe gets displayed perfectly in the name input field. However I do get an error: jinja2.exceptions.UndefinedError: 'saves' is undefined.
Why is that?
4 Answers
Andreas cormack
Python Web Development Techdegree Graduate 33,011 PointsHi Script Code
I have run your code and don't seem to get any errors !!
Alx Ki
Python Web Development Techdegree Graduate 14,822 PointsHi! Did you import render_template from flask?
Script Code
6,631 PointsYes :)
Alx Ki
Python Web Development Techdegree Graduate 14,822 PointsI tried your code in PyCharm - it has no errors. If you use PyCharm you should install Flask in the virtualenv of project folder. If you have Flask installed in project's virtualenv - send whole code here to check. else: Kenneth shows how to do it
Ivan Valderrama
Python Web Development Techdegree Student 10,588 PointsI have this exact same error message
Filip Hudecek
Full Stack JavaScript Techdegree Student 16,310 PointsSame error message for me
Script Code
6,631 PointsScript Code
6,631 PointsHi Andreas, a bit of a late response. I do get the errors. Maybe it's worth mentioning that I am using PyCharm.