Tornado Local Python Web Development Guide
Run Python applications on localhost using the Tornado asynchronous web framework, defaulting to http://localhost:8888.
Tornado is an asynchronous web framework and HTTP server for Python, suitable for long connections, WebSocket, and high-concurrency I/O. It comes with a built-in HTTP server, eliminating the need for additional Apache/Nginx for local development.
Default localhost Access
| Purpose | Address |
|---|---|
| Common example default | http://localhost:8888 |
| Custom port | Specified by listen() in code |
The official Tornado example commonly uses port 8888 (not mandatory, can be specified as needed).
Minimal Example
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hello from localhost")
app = tornado.web.Application([(r"/", MainHandler)])
app.listen(8888)
tornado.ioloop.IOLoop.current().start()After running, access http://localhost:8888.
Installation
pip install tornadoWebSocket
Tornado natively supports WebSocket, and during local debugging, the frontend connects to paths like ws://localhost:8888/ws.
Frequently Asked Questions
Port Occupied
Change to another port with app.listen(9090) or similar.
Conflict with Jupyter
Jupyter also commonly uses port 8888; do not occupy the same port simultaneously.
Summary
Tornado’s built-in server allows local development access at http://localhost:8888 (or the port configured in the code).