iSeriesPython

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/defaultfilters.py

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/__init__.py

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

  • use_system_version = False
    #try:
    # # 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' '0.0.0.0:') ALWMLTTHD(*YES)


on
/python27/site-packages/django/utils/autoreload.py

add subprocess :

  • import subprocess, os, sys, time

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


with
  • #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/ 127.0.0.1:4000
    ...

------------------------------------------------------------------------

and use this script for running your app (django_scgi.py) :

------------------------------------------------------------------------
  • #!/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
    WSGIServer(WSGIHandler(),bindAddress=('127.0.0.1',4000)).run()

-------------------------------------------------------------------------


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


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

  • STRTCPSVR SERVER(*HTTP) HTTPSVR(APACHEDFT)


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

For mod_scgi we need:

http://trac.saddi.com/flup

to put into:

/python27/site-packages/flup/server/