Page 1 of 1

Use javascript at web application.

PostPosted: Tue Jan 12, 2016 12:35 pm
by dwj
Hi,

I was able to build a web application with OMERO.web. Now I want to add some JavaScript logic into the web page. For this I wrote a js-file and store it next to the html file.
When I load the web application at the client I can see the content of the html page, but the js-file is not loaded. The error at the client browser is:
GET http://localhost:8080/WebHWorld/media/javaScript.js 404 (NOT FOUND)

The html file looks like this:
Code: Select all
<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript" src="javaScript.js"></script>
    </head>
    <body>
   <form action="/WebHWorld/" method="get">
      <!-- MY CONTENT-->
   </form>
   </body>
<!html>


What do I need to change to load a javascript file?

Thanks!

SOLVED: Use javascript at web application.

PostPosted: Wed Jan 13, 2016 7:36 am
by dwj
I have solved the problem. I have to put the javafile not next to the html file but inside a 'static' directory at the project directory.
The file is now at: 'ProjectDir/static/{ProjectName}/js/javaScript.js

At the html I changed the script source:
Code: Select all
<script type="text/javascript" src="{% static 'WebHWorld/js/javaScript.js' %}"></script>


After these changes the jacascript is loaded.

Re: Use javascript at web application.

PostPosted: Wed Jan 13, 2016 9:39 am
by atarkowska
Hi,

That is correct. Please refer to Django documentation for more details https://docs.djangoproject.com/en/1.8/h ... tic-files/

Ola