livepage.html   [plain text]


<?xml version="1.0"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><title>Twisted Documentation: LivePage</title><link href="../howto/stylesheet.css" type="text/css" rel="stylesheet" /></head><body bgcolor="white"><h1 class="title">LivePage</h1><div class="toc"><ol></ol></div><div class="content"><span></span><div class="note"><strong>Note: </strong><p>
This HOWTO documents the LivePage class, part of the Woven framework. The Woven framework should not be used for new projects. The newer <a href="http://www.divmod.org/Home/Projects/Nevow/">Nevow</a> framework, available as part of the <a href="http://www.divmod.org/Quotient/">Quotient</a> project, is a simpler framework with consistent semantics and better testing and is strongly recommended over Woven.
</p><p>
The Woven documentation below is maintained only for users with an existing Woven codebase. The LivePage HOWTO is just a quick bootstrap page in any case.
</p></div><img src="../img/livepage.png" alt="Overview of LivePage" title="Overview of LivePage" /><p>To use LivePage, subclass or instantiate <code class="API"><a href="http://twistedmatrix.com/documents/TwistedDocs/TwistedDocs-1.3.0/api/twisted.web.woven.page.LivePage.html" title="twisted.web.woven.page.LivePage">LivePage</a></code> instead of <code class="API"><a href="http://twistedmatrix.com/documents/TwistedDocs/TwistedDocs-1.3.0/api/twisted.web.woven.page.Page.html" title="twisted.web.woven.page.Page">Page</a></code>. Then, in your HTML template, include
the following HTML fragment somewhere towards the bottom of the page:</p><pre>
  &lt;span view=&quot;webConduitGlue&quot; /&gt;
</pre><p>Then, <a href="controllerindepth.html#eventhandlers">Event handlers</a> can forward
client-side JavaScript events to the Server, and you can send JavaScript to the
browser after a page has already loaded. Example:</p><pre>
class Foo(page.LivePage):
    template = ('&lt;html&gt;&lt;body&gt;'
                'Nothing here!&lt;span view=&quot;webConduitGlue&quot; /&gt;'
		'&lt;/body&gt;&lt;/html&gt;')
    def setUp(self, request):
        global currentPage

        # don't save this in a global but somewhere your code can get
        # to it later
        currentPage = request.getSession(interfaces.IWovenLivePage)

# then later, in response to some server-side event
def fooHappened():
    global currentPage

    currentPage.sendScript(&quot;alert('hello, world!')&quot;)
</pre></div><p><a href="../howto/index.html">Index</a></p><span class="version">Version: 1.3.0</span></body></html>