Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are plenty of examples in the <a href="http://twistedmatrix.com/documents/current/core/howto/" rel="nofollow">documentation of twisted</a>. If you prefer a quick <a href="http://jcalderone.livejournal.com/53465.html" rel="nofollow">summary on how to use sessions</a>.</p> <pre><code>from twisted.web.resource import Resource class ShowSession(Resource): def render_GET(self, request): return 'Your session id is: ' + request.getSession().uid class ExpireSession(Resource): def render_GET(self, request): request.getSession().expire() return 'Your session has been expired.' resource = ShowSession() resource.putChild("expire", ExpireSession()) </code></pre> <p>Do not forget that request.getsession() will create the session if it doesn't already exists. This tutorial explains <a href="http://jcalderone.livejournal.com/53680.html" rel="nofollow">how to store objects in session</a>.</p> <pre><code>cache() from zope.interface import Interface, Attribute, implements from twisted.python.components import registerAdapter from twisted.web.server import Session from twisted.web.resource import Resource class ICounter(Interface): value = Attribute("An int value which counts up once per page view.") class Counter(object): implements(ICounter) def __init__(self, session): self.value = 0 registerAdapter(Counter, Session, ICounter) class CounterResource(Resource): def render_GET(self, request): session = request.getSession() counter = ICounter(session) counter.value += 1 return "Visit #%d for you!" % (counter.value,) resource = CounterResource() </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload