Search |
||
Run Django applications on GlassFish v3 PreviewPosted by vivekp on June 5, 2009 at 9:41 AM PDT
GlassFish
v3 Preview is available
and I am excited to announce support for Django
applications. Django
is a Python based framework, probably anyone hosting their applications
on GAE might know Django is a Python based web framework.
GlassFish-Scripting project provides implementation of Jython
Container. Just like JRuby Container, Jython Container does the
following:
Here is how you can run a Jython application on GlassFish v3 Preview. Install GlassFish v3 PreviewFollow the directions from here to install GlassFish v3 Preview.Install Jython Container on GlassFish v3 Preview
$ cd /tools/glassfishv3
Below is the GlassFish v3 Update Tool image. Select GlassFish v3 Jython Container and click Install. This would install Jython Container OSGi module and Grizzly adapter jars inside glassfish/modules directory.
Install JythonTo run your Django application, at the minimum you need Jython 2.5 release. Get Jython 2.5 RC3 from here. Once downloaded, run the installer by doing the following:
$ java -jar jython_installer-2.5rc3.jar
Follow the installer direction and after it is installed, add jython command to your path
$ export JYTHON_HOME=/path/to/jython-install
should display jython interpreter shell ![]() Install DjangoGet Django 1.0.2 from here.
$ tar xzvf Django-1.0.2-final.tar.gz
Follow the detailed instruction here. Create a sample Django application
$ django-admin.py startproject mysite
Start GlassFish v3 Preview
$ asadmin start-domain -v
Above /tools/jython is where I installed jython. jython.home system property tells Jython container in GlassFish v3, where to find jython container. Deploy the application
$ cd mysite
Now access http://localhost:8080/mysite and it should show the first Django page:
Enable Django adminDjango framework comes with a built in administration utility and we will enable it in this sample. The admin application needs a database. So first we would need to setup the database.Install PostgreSQLDownload and install PostgreSQL database server. Make sure it is running.Once installed, make sure it is running. You would also need to download and install PostgreSQL JDBC driver inside jython installation.
$ cd /tools/jython
Above /tools/jython is where I have installed jython. Install django-jythonYou would need JDBC drivers for the database backends. So you would need to install django-jython on your Jython installation. django-jython is a Google Code project that has JDBC database backend for PostgreSQL only. There is SQLite3 experimantal version and no MySQL as of now.Download the latest django-jython from here. Then install it on Jython.
$ tar zxvf django-jython-1.0b1.tar.gz
See further details on setting up backend here. Create database$ createdb mysiteRefer to details on how to go about creating database in PostgreSQL incase you encounter problem. We will use mysite database in our Django application. Configure DatabaseEdit settings.py and change the database configuration. For example these are my entries:
DATABASE_ENGINE = 'doj.backends.zxjdbc.postgresql'
Above, doj.backends.zxjdbc.postgresql is the name of the PostgreSQL JDBC driver, the database name is mysite and then the username and password. HOST and PORT values are empty meaning the default will be taken. It is time to sync the DB. So first make the PostgreSQL JDBC driver available to jython classpath so that the following syncdb command works:
$ export CLASSPATH=/tools/jython/postgresql-8.3-604.jdbc4.jar:$CLASSPATH
NOTE: postgresql-8.3-604.jdbc4.jar was downloaded and installed inside jython directory installation earlier. Enable admin appEdit settings.py and add 'django.contrib.admin' under INSTALLED_APPS.
INSTALLED_APPS = (Edit urls.py and uncomment all the lines that contains admin. Make sure you do not have space at the beginning on a line. ![]() Now you would need to redeploy the application so that you can access the admin application. But before we do that, we need to make the stylesheets available to the Jython container.
$ asadmin deploy --property
jython.mediaRoot=/tools/jython/Lib/site-packages/django/contrib/admin/
--force=true .
There is a bug in Jython container and this would not work so as a work around copy the admin media files to the GlassFish v3 domain1 docroot. $ cp -r
/tools/jython/Lib/site-packages/django/contrib/admin/media
/tools/glassfishv3/glassfish/domains/domain1/docroot/
Note: If you deploy your application at context root '/' then the above work around to make admin media files will not be needed. Now access : http://localhost:8080/mysite/admin, it should show: ![]() After you login, the admin console would let you manage users/groups. ![]() To summarise
A note about the Ruby application support, GlassFish v3 Preview release improves on the Ruby application support. Now the Ruby application deployment support is Rack based. Just like WSGI, Rack is a Ruby standard to wire a web server to a Ruby web framework. The Ruby web frameworks supported out of the box are: Rails, Merb and Sinatra. Try it out by running on GlassFish v3 Preview and send us feedback at GlassFish mailing list. »
Related Topics >>
Web Applications Comments
Comments are listed in date ascending order (oldest first)
|
||
|
|