Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Flask Basics Character Builder Set a Cookie

Stacey Normington
Stacey Normington
4,718 Points

code challenge cookies

Kinda struggling with this one anyone know where I'm going wrong?

flask_app.py
from flask import Flask, make_response

app = Flask(__name__)


@app.route('/save')
def save():
    response = make_response() response.set_cookie('name', 'treehouse')
    return response.set_cookie

2 Answers

Indiya Gooch
Indiya Gooch
12,046 Points

Note: Edited as correct answer below this original answer

Your answer is nearly correct! The make response() end bracket is just misplaced:

@app.route('/save')
def save():
    response = make_response()
    response.set_cookie('name', 'treehouse')
    return response
Stacey Normington
Stacey Normington
4,718 Points

It's saying it didn't get a treehouse cookie the code i used was identical to yours is workspaces down?

Indiya Gooch
Indiya Gooch
12,046 Points

My apologies, the answer i gave was the one for the character builder which you'll progress onto soon enough. The answer you're looking for is as follows:

from flask import Flask
from flask.helpers import make_response

app = Flask(__name__)

@app.route('/save')
def save():
    response = make_response()
    response.set_cookie('treehouse','value')
    return response

make_response belongs to flask.helpers, so ensure you import it first. You can then make the response with the make_response() method, set a cookie on it, and return it.