How to load java applet from django template

2019-07-10 06:43发布

问题:

My applet runs file when I call it from a static applet.html file, like this:

<applet archive="applet.jar" code="com.xxx.yyy.PApplet" 
    width="100" height="20"></applet>

But how do I put the same line in a django template? And where should I put the .jar and .java files? I also noticed that it appends .class to the PApplet while looking for the file and sends me a 404 error.

I tried googling and looked into documentation, but couldn't find this issue addressed anywhere before. Thanks for your help.

回答1:

You should use your jar file as a static media file like an image ou CSS file via MEDIA_URL.

Put applet.jar in the media directory, then use

<applet archive="{{ MEDIA_URL }}applet.jar" code="com.xxx.yyy.PApplet" 
width="100" height="20"></applet>


回答2:

This has nothing whatsoever to do with Django.

A Java applet for client-side use needs to be served in exactly the same way as any other static assets - CSS, Javascript, etc. So you'd put it wherever those files are, configure Apache or whatever to serve from there, and reference that directory in your applet tag.