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 trialGinny Pennekamp
31,466 PointsHaving trouble with response.set_cookie
Can't pass the third stage because I'm not clearly understanding how to set a cookie.
I had an issue with passing this question in the quiz too. In the video, the cookie is set with response.set_cookie('character', json.dumps(dict(request.form.items()))) but in the quiz, the solution was the simple response.set_cookie('name', "Treehouse")...
in that case, shouldn't my code below pass? What am I misunderstanding/ doing wrong?
from flask import Flask
from flask import make_response
app = Flask(__name__)
@app.route('/save')
def save():
response = make_response(redirect(url_for('index')))
response.set_cookie('treehouse', "value")
return response
3 Answers
William Li
Courses Plus Student 26,868 PointsHi, Ginny, your set_cookie
is totally correct, but the problem is at the part two of the challenge, at this line of code
response = make_response(redirect(url_for('index')))
Part 2 is asking you to
Now add a variable named response and set it's value to make_response()
so you should simply just do this instead.
response = make_response()
That way your response will hold the correct value, and the response.set_cookie should work the way the challenge is expecting.
Ary de Oliveira
28,298 PointsIn the save() function, remove the pass statement. Now add a variable named response and set it's value to make_response(). You'll need to return the response variable.
response = make_response()
return response
Ginny Pennekamp
31,466 PointsThanks, William! That fixed it!
Mike Siwik
Front End Web Development Techdegree Student 14,814 PointsMike Siwik
Front End Web Development Techdegree Student 14,814 PointsThis challenge must be bugged or something. to complete task 2 out of 3 all you need is:
response = make_response(redirect(url_for('index')))
When it clearly asks you to return the response, but when you type in the return response, all you get are IndentationErrors.