Django on Jython Tips
February 16, 2010
I'm using Django on Jython so that I can deploy my app in Tomcat without needing to install a python runtime. This is for a packaged app, so not adding extra dependencies is good.
Installing
I installed Jython 2.5.1.
I then setup a project in Eclipse (using pydev) with django 1.1.1 in it, and django-jython 1.1.1 (the doj package).
Building a WAR File
You need to have 'doj'
in the your application's INSTALLED_APPLICATIONS
Once that is done, you can use python manage.py war
to create a standalone war file.
MEDIA_URL problem
I got this error:
OSError: [Errno 0] couldn't make directory: 'c:\\docume~1\\user\\locals~1\\temp\\tmp1zzcc7\\app\\http:localhost:8000'
This was caused by the fact that my MEDIA_URL was set to 'http://localhost:8000/site_media/'
. I fixed this problem by changing it to be just /site_media
MEDIA_URL = '/site_media/'
and the WAR file now creates fine. You need to remember to use {{MEDIA_URL}}
in HTML templates rather than hardcoded /site_media
.
Running
I got the error 'DatabaseWrapper' object has no attribute 'queries'
at runtime. Here are the database settings I was using:
DATABASE_ENGINE = '' DATABASE_NAME = '' DATABASE_USER = '' DATABASE_PASSWORD = '' DATABASE_HOST = '' DATABASE_PORT = ''
Even though I wasn't using a database connection from this app, I needed to set a database engine:
DATABASE_ENGINE = 'doj.backends.zxjdbc.postgresql'
Forms
I had a problem submitting forms. It was redirecting to / rather than to where I expected. The problem was because I was using action="."
in my form tag. action=""
fixed the problem.