1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
5 This example demostrates how to get host information from a request object.
7 To test the script, rename the file to report.rpy, and move it to any directory,
8 let's say /var/www/html/.
10 Now, start your Twist web server:
11 $ twistd -n web --path /var/www/html/
13 Then visit http://127.0.0.1:8080/report.rpy in your web browser.
16 from twisted.web.resource import Resource
19 class ReportResource(Resource):
21 def render_GET(self, request):
23 host = request.getHost().host
24 port = request.getHost().port
25 url = request.prePathURL()
27 secure = (request.isSecure() and "securely") or "insecurely"
30 <HEAD><TITLE>Welcome To Twisted Python Reporting</title></head>
32 <BODY><H1>Welcome To Twisted Python Reporting</H1>
34 <LI>The path to me is %(path)s
35 <LI>The host I'm on is %(host)s
36 <LI>The port I'm on is %(port)s
37 <LI>I was accessed %(secure)s
38 <LI>A URL to me is %(url)s
39 <LI>My URI to me is %(uri)s
44 resource = ReportResource()