In the pashmak web system, you can access cookies with $web.cookies
global variable.
For example:
import @web
web.init()
web.end_headers()
println($web.cookies)
output:
{'foo': 'bar', 'x': 'y'...}
The $web.cookies
variable is a dictonary. for example:
import @web
web.init()
web.end_headers()
println($web.cookies['cookie_name'])
You cannot directly change items in $web.cookies
variable. for setting cookies, you should use web.set_cookie()
function.
for example:
import @web
web.init()
web.set_cookie({
'name': 'cookie_name',
'value': 'value of cookie'
})
# remember to set the cookie BEFORE ending the headers
web.end_headers()
println($web.cookies)
You should pass a dictonar to this function and set the items. name
is name of cookie and value
is value of cookie.
Also you can set more options. for example expire
, path
, domain
…(All of cookie general options are available).