Alex, yes that worked. Here is my final product. I tried
request.write and I it is called twice. Then used return "????" with
not problem. Is return "??" as good as request.write?
----------------------------
from twisted.web.server import Site
from twisted.web.resource import Resource
from twisted.internet import reactor
from twisted.web.static import File
class PaymentRequired(Resource):
def render(self, request):
request.setResponseCode(402)
return "<html><body>Please swipe your credit card.</body></html>"
class menu(Resource):
def render_GET(self, request):
request.setResponseCode(402)
return """
<html>
<body>
Here is some text in menu.
</body>
</html>
"""
class HomePage(Resource):
def render(self, request):
request.setResponseCode(402)
return """
<html>
<head>
<title>Colors</title>
<link type='text/css' href='/css/styles.css'
rel='Stylesheet' />
</head>
<body>
<h1>Homepage Main</h1>
What's here:
<ul>
<li><a href='/buy'>This is the buy page</a></li>
<li><a href='/men'>This is the menu</a></li>
<li><a href='/rim'>This is using request write.</a></li>
</ul>
</body>
</html>
"""
class rwrite(Resource):
def render(self, request):
request.setResponseCode(402)
return"""
<html>
<head>
</head>
<body>
<h1>Colors index page</h1>
And a little text.
</body>
</html>
"""
root = Resource()
root.putChild('', HomePage())
root.putChild("foo", File("/tmp"))
root.putChild("bar", File("/lost+found"))
root.putChild("baz", File("/opt"))
root.putChild("varr", File("/var"))
root.putChild("buy", PaymentRequired())
root.putChild("men", menu())
root.putChild("rim", rwrite())
factory = Site(root)
reactor.listenTCP(3333, factory)
reactor.run()
-----------------------------
On Sep 30, 1:02 pm, Alex Clemesha <[email protected]> wrote:
> On Wed, Sep 30, 2009 at 11:53 AM, Mikie <[email protected]> wrote:
>
> > No, Alex. It will not access the paymentRequired page.
>
> Make this change and it should work:
>
> class menu(Resource):
> def render_GET(self, request):
> request.setResponseCode(402)
> return "<html><body><a href='/buy'>Integrater</a></body></html>"
>
> Note the " href='/buy'".
>
> Does this work for you now?
> -Alex
>
>
>
>
>
>
>
> > On Sep 30, 11:28 am, Alex Clemesha <[email protected]> wrote:
> >> > root = Resource()
> >> > root.putChild("foo", File("/tmp"))
> >> > root.putChild("bar", File("/lost+found"))
> >> > root.putChild("baz", File("/opt"))
> >> > root.putChild("varr", File("/var"))
> >> > root.putChild("buy", PaymentRequired())
> >> > root.putChild("men", menu())
> >> > factory = Site(root)
> >> > reactor.listenTCP(3333, factory)
> >> > reactor.run()
> >> > ----------------------------------------------
> >> > It will not load the second page.
>
> >> Do you mean that it will not load the page that
> >> shows the contents of "/lost+found"? Maybe there
> >> is a problem accessing that directory in the filesystem?
> >> Apologies if this is not the question you are asking.
>
> >> -Alex
>
> >> > On Sep 29, 8:55 pm, William Stein <[email protected]> wrote:
> >> >> On Tue, Sep 29, 2009 at 5:12 PM, Alex Clemesha <[email protected]>
> >> >> wrote:
>
> >> >> > On Tue, Sep 29, 2009 at 4:42 PM, William Stein <[email protected]>
> >> >> > wrote:
>
> >> >> >> On Tue, Sep 29, 2009 at 4:41 PM, Alex Clemesha <[email protected]>
> >> >> >> wrote:
>
> >> >> >>> On Tue, Sep 29, 2009 at 8:26 AM, Mikie <[email protected]>
> >> >> >>> wrote:
>
> >> >> >>>> Does anyone have an example of a twisted server that loads 2 html
> >> >> >>>> pages from a url?
> >> >> >>>> --www.twisted.com:8000/page1/,www.twisted.com:8000/page2/
> >> >> >>>> Same port.
> >> >> >>> Here are some very nice Twisted web tutorials:
> >> >> >>>http://jcalderone.livejournal.com/tag/sixty+seconds
>
> >> >> >>> You'll be able to figure out you above question, and more,
> >> >> >>> pretty easily from them. Send another email if you're still having
> >> >> >>> trouble after checking those out.
>
> >> >> >>> -Alex
>
> >> >> >> Alex, how hard is it to migrate from "Twisted.web2" which is used in
> >> >> >> Sage back to "Twisted.web"?
> >> >> > Pretty easily actually... the Resource object is pretty similar, the
> >> >> > main difference is that the Web2 Resource object has the
> >> >> > "locateChild" method,
> >> >> > where as the Web Resource has "getChild" - and even those are pretty
> >> >> > similar.
>
> >> >> > Also, there's some subtle differences in the way you doing
> >> >> > "rendering"... i.e. with Web2 you subclass Resource/PostableResource
> >> >> > and then
> >> >> > you use the "render" method, where are with Web you just subclass
> >> >> > Resource
> >> >> > and implemented either "render_GET" or "render_POST".
>
> >> >> > Probably just looking through the examples here:
> >> >> >http://jcalderone.livejournal.com/tag/sixty+seconds
> >> >> > would be good enough to do the switch.
>
> >> >> > The Web code is being actively maintained and improved... One
> >> >> > major improvement that will being going into Twisted 9.0 (due
> >> >> > tomorrow on
> >> >> > the Twisted trac actually), is the nice WSGI support (for running
> >> >> > Django, etc).
> >> >> > In Codenode we use the trunk Web code, but in just a couple of days we
> >> >> > will be able to remove all that code, and very cleanly run Django off
> >> >> > a
> >> >> > standard install of Twisted, which is extremely convenient.
>
> >> >> Thanks. That was incredibly helpful and greatly appreciated.
>
> >> >> William- Hide quoted text -
>
> >> >> - Show quoted text -
>
> >> --
> >> Alex Clemesha
> >> clemesha.org- Hide quoted text -
>
> >> - Show quoted text -
>
> --
> Alex Clemesha
> clemesha.org- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---