我是uisng python,要将数据从json文件显示到页面,我收到以下错误
Failed to load resource: the server responded with a status of 404 (NOT FOUND) http://localhost:8000/static/script/jquery-1.9.1.min.js
Failed to load resource: the server responded with a status of 404 (NOT FOUND) http://localhost:8000/static/script/myscript.js
Run Code Online (Sandbox Code Playgroud)
myscript.js文件
$("#button").click(function(){
$.getJSON("item.json",function(obj){
$.each(obj,function(key,value){
$("ul").append("<li>+value.item1+"</li>");
$("ul").append("<li>+value.item2+"</li>");
$("ul").append("<li>+value.item3+"</li>");
});
});
});
Run Code Online (Sandbox Code Playgroud)
.json文件是
{
"p1":{
"item1":"apple",
"item2":"orange",
"item3":"banana",
},
"p2":{
"item1":"water",
"item2":"milk",
"item3":"alcohol",
}
}
Run Code Online (Sandbox Code Playgroud)
模板是
<html>
<head>
<body>
<ul></ul>
<button></button>
<script src="script/jquery-1.9.1,min.js" type="text/javascript"></script>
<script src="script/myscript.js" type="text/javascript"></script>
</body>
</head>
</html>
Run Code Online (Sandbox Code Playgroud)
1).js文件在我的项目文件夹中,并且路径也已设置.
2).我是不是做在我的views.py任何疑问,因为我是新来这个,我很困惑与this.So任何值编码需要在views.py从JSON获取数据来执行.
3).无法解决上述错误,请提供可能的原因,以便我可以运行此功能.
谢谢
您必须在 django 设置文件中设置STATIC_URL
和STATIC_ROOT
,在 js src 路径前面添加{{ STATIC_URL }}
,并告诉 django 在使用开发服务器时提供静态内容(和/或配置前端服务器来提供服务)。这一切都记录在这里:https ://docs.djangoproject.com/en/1.4/ref/contrib/staticfiles/
注意:在 1.3 版本之前,它是 MEDIA_URL 和 MEDIA_ROOT,请参见相关文档。
归档时间: |
|
查看次数: |
11882 次 |
最近记录: |