setting a cookie in flask

I am trying to create a cookie in flask. The partial example in the manual is:

resp = make_response(render_template(...))
resp.set_cookie(’username’, ’the username’)

So I implement it as

resp = render_template('show_entries.html', AO_sInteger = session.get('AO_sInteger'))
resp.set_cookie('AO_sInteger', AO_sInteger)

The system then returns with the error:

File "...\Flaskr101.py", line 19, in add_entry
resp.set_cookie('AO_sInteger', AO_sInteger)
AttributeError: 'unicode' object has no attribute 'set_cookie'

How can I fix this problem?

Best answer

In the manual resp is:

resp = make_response(render_template(...))

and in your code it is:

resp = render_template('show_entries.html', AO_sInteger = session.get('AO_sInteger'))

Make it a proper response object by using make_response:

from flask import make_response
resp = make_response(render_template('show_entries.html', AO_sInteger = session.get('AO_sInteger')))