javascript - Django Static js files not working - Stack Overflow

Well my template code.<!DOCTYPE html><html><head>{% load staticfiles %}<script

Well my template code.

<!DOCTYPE html>
<html>
<head>
{% load staticfiles %}
    <script type="text/javascript" src=".min.js"></script>
    <script type="text/javascript" src="{% static 'website/staffaddproblem.js' %}"></script>
    <title>Dashboard</title>
    <link href="{% static 'website/style.css' %}" rel="stylesheet" type="text/css"/>
</head>
<body>
        body
</body>
<html>

As you can see it has a css file. which is working properly, but java script file does not work. when i load the page its source looks like this.

When i click the link it loads the file too its there its linking fine but its not working . there is no problem in code js code working fine when written in same file.

Well my template code.

<!DOCTYPE html>
<html>
<head>
{% load staticfiles %}
    <script type="text/javascript" src="http://code.jquery./jquery-latest.min.js"></script>
    <script type="text/javascript" src="{% static 'website/staffaddproblem.js' %}"></script>
    <title>Dashboard</title>
    <link href="{% static 'website/style.css' %}" rel="stylesheet" type="text/css"/>
</head>
<body>
        body
</body>
<html>

As you can see it has a css file. which is working properly, but java script file does not work. when i load the page its source looks like this.

When i click the link it loads the file too its there its linking fine but its not working . there is no problem in code js code working fine when written in same file.

Share Improve this question asked Aug 17, 2015 at 7:02 Ayub KhanAyub Khan 8962 gold badges14 silver badges17 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 11

Have you changed the settings.py file to include staticroot?

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

Here's a part of my template which works with both js and css files.

{% load static %}
<html>
<head>
<link type="text/css" rel="stylesheet" href="{% static 'css/materialize.min.css' %}">
<link type="text/css" rel="stylesheet" href="{% static 'css/stylesheet.css' %}">
<script type="text/javascript" src="{% static 'js/jquery-1.11.3.min.js' %}"></script>
<title>

The directories are as follows:

 - static
     -js
         - jquery-1.11.3.min.js
     -css     
         - stylesheet.css
         - materialize.min.css
 - templates
     -index.html

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743641269a4483002.html

相关推荐

  • javascript - Django Static js files not working - Stack Overflow

    Well my template code.<!DOCTYPE html><html><head>{% load staticfiles %}<script

    7天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信