Set cookie in bulb

I am trying to create a cookie in a bulb. A partial example in the manual:

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

Therefore, I implement it as

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

Then the system returns with an 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?

+4
source share
1 answer

The resp manual contains:

 resp = make_response(render_template(...)) 

and in your code this is:

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

Make it a suitable response object using make_response :

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

All Articles