home     documentation     download     Spyce logo


[[.import name=cookie]]
  Managing cookies is simple. Use the following forms 
  to create and destroy cookies. Remember to refresh 
  once, because the cookie will only be transmitted on 
  the <i>following</i> request.<br>
  [[-- input forms --]]
  <form action="[[=request.uri('path')]]" method=post>
      <td align=right>Cookie name:</td>
      <td><input type=text name=name></td>
      <td align=right>value:</td>
      <td><input type=text name=value></td>
      <td>(required for set)</td>
      <td align=right>expiration:</td>
      <td><input type=text name=exp> seconds.</td>
      <td colspan=3>
        <input type=submit name=operation value=set>
        <input type=submit name=operation value=delete>
        <input type=submit name=operation value=refresh>
  [[-- show cookies --]]
  Cookies: [[=len(cookie.get().keys())]]<br>
    [[for c in cookie.get().keys(): {]]
    [[ } ]]
  [[-- set cookies --]]
    operation = request.post('operation')
    if operation:
      operation = operation[0]
      name = request.post('name')[0]
      value = request.post('value')[0]
      if operation == 'set' and name and value:
        cookie.set(name, value)
      if operation == 'delete' and name:
Run this code

Back to List of Examples

Spyce logo
Python Server Pages
version 2.1.3
Spyce Powered SourceForge Logo