Table Of Contents

Previous topic

Internals

Next topic

Utilities

This Page

TxWeb

A module based on twisted web for running asynchronous HTTP servers which can be used to expose RPC or django-powered web applications.

Django Application

Utility module for creating an asyncronous web-server which runs a django-wsgi application. Let’s assume you have a django site called mysite. Add a new file into mysite directory with the following:

import os
import sys
import manage
from unuk.contrib.txweb import djangoapp, start

def get_webserver(mediadir = "media", port = None):
    local_dir = os.path.split(os.path.abspath(__file__))[0]
    return djangoapp.ApplicationServer(local_dir, port = port, mediadir = mediadir)

if __name__ == '__main__':
    server = get_webserver(mediadir="media", port=9000)
    start()

The twisted server will serve the media file for you, without going into the django views. Make sure your settings has:

MEDIA_URL = '/media/'
ADMIN_MEDIA_PREFIX = '/media/admin/'

RPC-JSON Application