简体   繁体   English

Django静态js文件无法正常工作

[英]Django Static js files not working

Well my template code. 好吧,我的模板代码。

<!DOCTYPE html>
<html>
<head>
{% load staticfiles %}
    <script type="text/javascript" src="http://code.jquery.com/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. 如您所见,它有一个css文件。 which is working properly, but java script file does not work. 哪个工作正常,但java脚本文件不起作用。 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. 代码js代码在同一文件中编写时没有问题。

Have you changed the settings.py file to include staticroot? 您是否更改了settings.py文件以包含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. 这是我的模板的一部分,它适用于jscss文件。

{% 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM