1

I'm using django development server to study how to create template. But my local js file not loading. The js is working fine in jsfiddle.

Here's my html file.

{% load staticfiles %}
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<link rel="stylesheet" type="text/css" href="{% static "css/encoder_view.css" %}" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<!--This external file-->
<script type="text/javascript" scr="{% static "js/encoder_view.js" %}"></script> 

</head>
<body>
<table>
 <tr id="top-border">       
  <td width="120">     
    <input id="check-all" class="checkbox" name="selector" type="checkbox" style="width:15px;"/>
     <span id="testcheck">Check All</span>
  </td>    
 </tr>
</table>    
</body>
</html>

Following Thomas Orozco instruction and after using manage.py collectstatic all my static files is now in D:\Test_app\static directory

In my settings.py file:

STATIC_ROOT = 'D:/Test_app/static/'

STATIC_URL = '/static/'

STATICFILES_DIRS = ( "D:/Test_app/static",)

INSTALLED_APPS = ( 'django.contrib.staticfiles', ...

Can anyone give me direction how to solve this. Thanks in advance!

2 Answers 2

1

I know I'm a little late, but another possible solution to this would be to change "scr" to "src" in <script type="text/javascript" scr="{% static "js/encoder_view.js" %}"></script>.

Sign up to request clarification or add additional context in comments.

Comments

0

Try this: <script type="text/javascript" src="/static/js/encoder_view.js"></script>

2 Comments

Thanks Gimmy, hardcoding the url did the job. I was in the impression the {% static "js/encoder_view.js" %} will do this automatically.
You can look at the source produced to check that the url was composed correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.