Django on iSeries

Thanks to Massimo for putting this one together!


Copy from the django-1.3.tar.gz the django subdir on /python27/site-packages

1) /python27/site-packages/django/template/

because iseries c/400 compiler don't handle "inf" for floating point errors ,
only for passing the test , replace :

  • pos_inf = 1e200 * 1e200
    neg_inf = -1e200 * 1e200
    nan = (1e200 * 1e200) / (1e200 * 1e200)
    special_floats = [str(pos_inf), str(neg_inf), str(nan)]

with :

  • #pos_inf = 1e100 * 1e100
    #neg_inf = -1e100 * 1e100
    #nan = (1e100 * 1e100) / (1e100 * 1e100)
    #special_floats = [str(pos_inf), str(neg_inf), str(nan)]
    special_floats = [\"inf\",\"-inf\",\"nan\"]

2) /python27/site-packages/django/utils/simplejson/

there is a wrapper that i not found on python windows or linux version
/python27/lib/ that cause error because is not original simplejson that django search
(with .__version__ module)
comment out :

  • use_system_version = False
    # # The system-installed version has priority providing it is either not an
    # # earlier version or it contains the C speedups.
    # import simplejson
    # if (simplejson.__version__.split('.') >= __version__.split('.') or
    # hasattr(simplejson, '_speedups')):
    # from simplejson import *
    # use_system_version = True
    #except ImportError:
    # pass

(on linux or window import simplejson go on \"except ImportError\" and pass...)

3) This patch is needed for running django with internal server
(useful because it reload itseft at every change on the source
but on my iseries consume 10% of cpu always) :

  • SBMJOB CMD(CALL PYTHON('//manage' 'runserver' '') ALWMLTTHD(*YES)


add subprocess :

  • import subprocess, os, sys, time

replace :
  • exit_code = os.spawnve(os.P_WAIT, sys.executable, args, new_environ)

  • #exit_code = os.spawnve(os.P_WAIT, sys.executable, args, new_environ)
    exit_code = subprocess.Popen([sys.executable] + args[1:], env=new_environ).wait()

4) for production use the mod_scgi *SRVPGM with IBM http server (and CPU used when needed)

on http.conf add :
  • ...
    LoadModule scgi_module /QSYS.LIB/PYTHON27.LIB/MOD_SCGI.SRVPGM
    SCGIMount /django/


and use this script for running your app ( :

  • #!/usr/bin/env python
    import os

    # replace \"mysite\" with the name of your django app

    os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

    if __name__ == '__main__':
    from flup.server.scgi import WSGIServer
    from django.core.handlers.wsgi import WSGIHandler


  • SBMJOB CMD(CALL PYTHON('/where is your app/') ALWMLTTHD(*YES)

i use the default APACHEDFT server and the http.conf is on /www/apachedft/conf


point your browser on http://iseries ip/django

For mod_scgi we need:

to put into: