2017-04-23 172 views
0

我有一个简单的项目,使用Django 1.11和Javascript不工作。当我在HTML中运行js时,json加载和javascripts工作,但是当我将所有这些放入静态文件夹时,javascript加载但没有执行任何操作。我配置了静态文件夹,它加载了CSS配置,但不适用于JavaScript。我也运行collectstatics没有成功。你能帮忙吗?(Django +外部JavaScript)不工作

JS:

(function(){ 
     'use strict'; 
     window.onload = function(){ alert("Hi there"));} 
     var SentimientosApp = angular.module('SentimientosApp', []); 
     SentimientosApp.controller('SentimientosCtrl', function ($scope, $http){ 
     $http.get("../externalfiles/countries.json").success(function(data) { 
      $scope.datos = data; 
     }); 
     }); 
    }()); 

网/ sentimientos/index.html中:

{% load static %} 
<html ng-app="SentimientosApp"> 
<head> 
    <meta charset="utf-8"> 
    <title>Angular.js JSON Fetching Example</title> 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css"> 
    <link rel="stylesheet" href="{% static 'css/css.css' %}"> 
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js"></script> 

    <script type="text/javascript" src="{% static 'js/sentimientos.js' %}"></script> 

</head> 
{% block content %} 
<body ng-controller="SentimientosCtrl"> 
{% block title %}Articles for {{ year }}{% endblock %} 
<h2>Angular.js JSON Fetching Example</h2> 
<table> 
    <tr> 
     <th>Code</th> 
     <th>Country</th> 
     <th>Population</th> 
    </tr> 
    <tr ng-repeat="d in datos"> 
     {% verbatim %} 
     <td>{{d.code}}</td> 
     <td>{{d.name}}</td> 
     <td>{{d.population}}</td> 
     <td><input type="text" ng-model="new_title"/>{{ new_title }}</td> 
     {% endverbatim %} 
    </tr> 
</table> 
</body> 
{% endblock %} 
</html> 

JSON位于文件夹中的静态中与此相同的结构:

http://ladimi.com/bigdata/externalfiles/countries.json

文件夹结构如下所示:

\---web 
    +---crawler 
    | +---crawluniandes 
    | | +---.settings 
    | | +---crawluniandes 
    | | | +---spiders 
    | | | | \---__pycache__ 
    | | | \---__pycache__ 
    | | +---xmlnotepadsetup 
    | | +---XSL 
    | | \---__pycache__ 
    | +---migrations 
    | | \---__pycache__ 
    | +---static 
    | | +---css 
    | | | \---AMLG_CSS 
    | | +---doc 
    | | +---img 
    | | | \---buttons 
    | | \---js 
    | |  \---vendor 
    | +---Templates 
    | +---XMLs 
    | \---__pycache__ 
    +---rss 
    | +---migrations 
    | | \---__pycache__ 
    | +---static 
    | | \---css 
    | |  \---images 
    | +---Templates 
    | \---__pycache__ 
    +---sentimientos 
    | +---media 
    | +---migrations 
    | | \---__pycache__ 
    | +---static 
    | | +---css 
    | | +---externalfiles 
    | | \---js 
    | +---templates 
    | | \---sentimientos 
    | \---__pycache__ 
    +---static 
    | +---admin 
    | | +---css 
    | | +---fonts 
    | | +---img 
    | | | \---gis 
    | | \---js 
    | |  +---admin 
    | |  \---vendor 
    | |   +---jquery 
    | |   \---xregexp 
    | +---css 
    | | \---AMLG_CSS 
    | +---doc 
    | +---externalfiles 
    | \---js 
    |  \---vendor 
    \---web 
     \---__pycache__ 

当我检查的Firefox网络监测,JSON没有出现,仿佛JS从来没有卡列斯它:

Click to see the network monitor image

+0

您是否获得404对JavaScript的资产? –

+0

它得到200或304 – vlad0x

回答