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 Flask Basics Character Builder Set a Cookie

Stacey Normington
Stacey Normington
5,861 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

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
5,861 Points

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

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.