Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying with Django-Jython, and Tomcat?

I have a Django app we're attempting to deploy to a Tomcat server, using django-jython.

Just to test things, I've created the WAR archive file for a empty Django app successfully. The test Django application is called "chair".

Our Tomcat server apparently doesn't like WAR archives files, so I exploded (unzipped this), and copied these files to the server.

The webserver admin has created a context for me, and a directory for that context (mediatracking).

I've copied the files from the WAR archive into that directory, and I'm not quite sure how to get that test app to "run" now?

\mediatracking
 - application.py 
 - application$py.class 
 \WEB-INF 
   web.xml 
   \lib 
    - jruby-extras-fileservlet.jar 
    - jython.jar 
   \lib-python 
     - Lib.pth 
     - README 
     \chair 
     \django 
     \doj 
     \Lib 

etc. (I haven't descended lower than that in the chair/django/doj/Lib directory.)

Is there anything obvious missing from the above directory structure?

And how exactly do I get the Tomcat server to actually "run" this app? It doesn't run automatically if you go to the context directory (and there's only a application.py and application$py.class file there, so I'm not sure how it would).

Do I need to ask my webserver admin to do something with the web.xml file? I checked that, and there doesn't seem to be anything in there that would help this app run either:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
  <display-name>chair</display-name>
  <description>
   chair through WSGI with modjy
  </description>
  <context-param>
    <param-name>files.prefix</param-name> <!-- Needed by fileservlet -->
    <param-value></param-value>
   </context-param>
  <servlet>
    <servlet-name>modjy</servlet-name>
    <servlet-class>com.xhaus.modjy.ModjyJServlet</servlet-class>
    <init-param>
      <param-name>reload_on_mod</param-name>
      <param-value>1</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet>
    <servlet-name>fileservlet</servlet-name>
    <servlet-class>org.jruby.webapp.FileServlet</servlet-class>
  </servlet>


  <servlet-mapping>
    <servlet-name>fileservlet</servlet-name>
    <url-pattern>/media/*</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>modjy</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>
</web-app>

Any advice at all would be greatly appreciated =).

Cheers, Victor

like image 285
victorhooi Avatar asked Jul 02 '10 01:07

victorhooi


People also ask

What server does Django use for deployment?

Django primarily uses WSGI for the deployment of web applications. Django uses different WSGI servers which include: To install apache and mod_wsgi, execute the following commands.

What is the use of Django framework?

Django framework efficiently handles and generates dynamically HTML web pages that are visible to the end-user. Django mainly functions with a backend so, in order to provide a frontend and provide a layout to our website, we use templates. There are two methods of adding the template to our website depending on our needs.

What does Django mean?

Django is a rapid web development framework that can be used to develop fully fleshed web applications in a short period of time. The last but not least reason to learn Django is Python, Python has a huge library and features such as Web Scrapping, Machine Learning, Image Processing, Scientific Computing, etc.

What is a Django template?

A Django template is a text document or a Python string marked-up using the Django template language. Some constructs are recognized and interpreted by the template engine. The main ones are variables and tags.


1 Answers

This is a late answer, but I hadn't seen this question so far. Hope it still helps. Here are the steps I always follow (successfully).

1) Create the war file:

manage war --include-java-libs "...your external jars here..." --context-root=chair

The name of context-root is important because Django-on-Jython will manipulate your settings.py file and modify your MEDIA_URL and ADMINMEDIA_URL to add that context (e.g. MEDIA_URL = '/chair/media/'), and it must be the same context that you deploy to in Tomcat. It will be the same name of the generated war file (in this case chair.war). In external JARs include at least your JDBC drivers.

2) Deploy the war to Tomcat (has never been a problem in any Tomcat I used, versions 5 and 5.5). I do it manually through the HTML manager app at URL http://server:8080/manager/html - it will require authentication, use a username/password that has manager privileges in Tomcat's conf/users.xml I think (I'm writing from memory). There are plenty ways to automate this with Ant, Maven or other tools, but manual is just fine.

If you absolutely have to unwar the file manually, use a folder name that is exactly the same of the war file (and thus the context-root), in this case webapps/chair in the Tomcat install folder.

3) Access your deployed app from URL http://server:8080/chair/ (plus any additional url path as defined in urls.py)

The Modjy servlet is the one running serving your urls, as defined in:

  <servlet-mapping>
    <servlet-name>modjy</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>

If you don't see what you expect at http://server:8080/chair/ check in the HTML manager whether the app was really started, and check your Tomcat logs for errors (typically logs/catalina.out at the tomcat installation dir).

More info in the official doc: http://packages.python.org/django-jython/war-deployment.html

like image 140
Carles Barrobés Avatar answered Sep 17 '22 13:09

Carles Barrobés