我有一個簡單的項目,使用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從來沒有卡列斯它:
您是否獲得404對JavaScript的資產? –
它得到200或304 – vlad0x